Skip to content

Commit 5ce10a5

Browse files
committed
refactor a few lines out of YieldSubsequentResults
1 parent ffbfd3c commit 5ce10a5

File tree

1 file changed

+51
-29
lines changed

1 file changed

+51
-29
lines changed

spec/Section 6 -- Execution.md

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,12 @@ YieldIncrementalResults(data, errors, incrementalDataRecords):
356356
- Add {incrementalDataRecord} to {graph} as a new Pending Data node directed
357357
from the {pendingResults} that it completes, adding each of {pendingResults}
358358
to {graph} as new nodes, if necessary, each directed from its {parent}, if
359-
defined, recursively adding each {parent} as necessary.
360-
- Prune root nodes of {graph} containing no direct child Incremental Data
361-
Records, repeatedly if necessary, promoting any direct child Deferred
362-
Fragments of the pruned nodes to root nodes. (This ensures that no empty
363-
fragments are reported as pending).
364-
- Let {newPendingResults} be the set of root nodes in {graph}.
365-
- Let {pending} be the result of {GetPending(newPendingResults)}.
366-
- Let {hasNext} be {true}.
367-
- Yield an unordered map containing {data}, {errors}, {pending}, and {hasNext}.
359+
defined, recursively adding each {parent} as necessary until
360+
{incrementalDataRecord} is connected to {graph}.
361+
- Let {pendingResults} be the result of {GetNonEmptyNewPending(graph)}.
362+
- Prune root nodes from {graph} not in {pendingResults}, repeating as necessary
363+
until all root nodes in {graph} are also in {pendingResults}.
364+
- Yield the result of {GetInitialResult(data, errors, pending)}.
368365
- For each completed child Pending Incremental Data node of a root node in
369366
{graph}:
370367
- Let {incrementalDataRecord} be the Pending Incremental Data for that node;
@@ -380,7 +377,7 @@ YieldIncrementalResults(data, errors, incrementalDataRecords):
380377
parents.
381378
- Let {hasNext} be {false}, if {graph} is empty.
382379
- Yield an unordered map containing {completed} and {hasNext}.
383-
- Continue to the next completed child Incremental Data node in {graph}.
380+
- Continue to the next completed Pending Incremental Data node.
384381
- Replace {node} in {graph} with a new node corresponding to the Completed
385382
Incremental Data for {result}.
386383
- Add each {incrementalDataRecord} of {incrementalDataRecords} on {result} to
@@ -390,7 +387,7 @@ YieldIncrementalResults(data, errors, incrementalDataRecords):
390387
- Let {completedIncrementalDataNodes} be the set of completed Incremental Data
391388
nodes that are children of {completedDeferredFragments}.
392389
- If {completedIncrementalDataNodes} is empty, continue to the next completed
393-
child Incremental Data node in {graph}.
390+
Pending Incremental Data Node.
394391
- Initialize {incremental} to an empty list.
395392
- For each {node} of {completedIncrementalDataNodes}:
396393
- Let {incrementalDataRecord} be the corresponding record for {node}.
@@ -402,32 +399,57 @@ YieldIncrementalResults(data, errors, incrementalDataRecords):
402399
- Append {GetCompletedEntry(pendingResult)} to {completed}.
403400
- Remove {pendingResult} from {graph}, promoting its child nodes to root
404401
nodes.
405-
- Prune root nodes of {graph} containing no direct child Incremental Data
406-
Records, as above.
407-
- Let {hasNext} be {false} if {graph} is empty.
408-
- Let {incrementalResult} be an unordered map containing {hasNext}.
409-
- If {incremental} is not empty, set the corresponding entry on
410-
{incrementalResult} to {incremental}.
411-
- If {completed} is not empty, set the corresponding entry on
412-
{incrementalResult} to {completed}.
413-
- Let {newPendingResults} be the set of new root nodes in {graph}, promoted by
414-
the above steps.
415-
- If {newPendingResults} is not empty:
416-
- Let {pending} be the result of {GetPending(newPendingResults)}.
417-
- Set the corresponding entry on {incrementalResult} to {pending}.
418-
- Yield {incrementalResult}.
402+
- Let {newPendingResults} be a new set containing the result of
403+
{GetNonEmptyNewPending(graph, pendingResults)}.
404+
- Add all nodes in {newPendingResults} to {pendingResults}.
405+
- Prune root nodes from {graph} not in {pendingResults}, repeating as
406+
necessary until all root nodes in {graph} are also in {pendingResults}.
407+
- Let {pending} be the result of {GetPendingEntry(newPendingResults)}.
408+
- Yield the result of {GetIncrementalResult(graph, incremental, completed,
409+
pending)}.
419410
- Complete this incremental result stream.
420411

421-
GetPending(newPendingResults):
412+
GetNonEmptyNewPending(graph, oldPendingResults):
413+
414+
- If not provided, initialize {oldPendingResults} to the empty set.
415+
- Let {rootNodes} be the set of root nodes in {graph}.
416+
- For each {rootNode} of {rootNodes}:
417+
- If {rootNodes} is in {oldPendingResults}:
418+
- Continue to the next {rootNode}.
419+
- If {rootNode} has no children Pending Incremental Data nodes:
420+
- Let {children} be the set of child Deferred Fragment nodes of {rootNode}.
421+
- Remove {rootNode} from {rootNodes}.
422+
- Add each of the nodes in {children} to {rootNodes}.
423+
- Return {rootNodes}.
424+
425+
GetInitialResult(data, errors, pendingResults):
426+
427+
- Let {pending} be the result of {GetPendingEntry(pendingResults)}.
428+
- Let {hasNext} be {true}.
429+
- Return an unordered map containing {data}, {errors}, {pending}, and {hasNext}.
430+
431+
GetPendingEntry(pendingResults):
422432

423433
- Initialize {pending} to an empty list.
424-
- For each {newPendingResult} of {newPendingResults}:
425-
- Let {id} be a unique identifier for {newPendingResult}.
426-
- Let {path} and {label} be the corresponding entries on {newPendingResult}.
434+
- For each {pendingResult} of {pendingResult}:
435+
- Let {id} be a unique identifier for {pendingResult}.
436+
- Let {path} and {label} be the corresponding entries on {pendingResult}.
427437
- Let {pendingEntry} be an unordered map containing {id}, {path}, and {label}.
428438
- Append {pendingEntry} to {pending}.
429439
- Return {pending}.
430440

441+
GetIncrementalResult(graph, incremental, completed, pending):
442+
443+
- Let {hasNext} be {false} if {graph} is empty, otherwise, {true}.
444+
- Let {incrementalResult} be an unordered map containing {hasNext}.
445+
- If {incremental} is not empty:
446+
- Set the corresponding entry on {incrementalResult} to {incremental}.
447+
- If {completed} is not empty:
448+
- Set the corresponding entry on {incrementalResult} to {completed}.
449+
- If {pending} is not empty:
450+
- Set the corresponding entry on {incrementalResult} to {pending}.
451+
- Return {incrementalResult}.
452+
431453
GetIncrementalEntry(incrementalDataRecord, graph):
432454

433455
- Let {deferredFragments} be the Deferred Fragments incrementally completed by

0 commit comments

Comments
 (0)