-
Notifications
You must be signed in to change notification settings - Fork 105
Fix Conflate Stale Rendering Logic for Short Circuit #1263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,19 +161,12 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn( | |
} | ||
|
||
/** | ||
* If [runtimeConfig] contains [RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES] then | ||
* send any output, but return true which means restart the runtime loop and process another | ||
* action. | ||
* If [runtimeConfig] contains [RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES] and | ||
* we have not changed state, then return true to short circuit the render loop. | ||
*/ | ||
suspend fun shortCircuitForUnchangedState(actionResult: ActionProcessingResult): Boolean { | ||
if (runtimeConfig.contains(RENDER_ONLY_WHEN_STATE_CHANGES) && | ||
fun shouldShortCircuitForUnchangedState(actionResult: ActionProcessingResult): Boolean { | ||
return runtimeConfig.contains(RENDER_ONLY_WHEN_STATE_CHANGES) && | ||
actionResult is ActionApplied<*> && !actionResult.stateChanged | ||
) { | ||
// Possibly send output and process more actions. No state change so no re-render. | ||
sendOutput(actionResult, onOutput) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
scope.launch { | ||
|
@@ -183,34 +176,40 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn( | |
// launched. | ||
var actionResult: ActionProcessingResult = runner.processAction() | ||
|
||
if (shortCircuitForUnchangedState(actionResult)) continue | ||
if (shouldShortCircuitForUnchangedState(actionResult)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is much better. |
||
sendOutput(actionResult, onOutput) | ||
continue | ||
} | ||
|
||
// After resuming from runner.processAction() our coroutine could now be cancelled, check so | ||
// we don't surprise anyone with an unexpected rendering pass. Show's over, go home. | ||
if (!isActive) return@launch | ||
|
||
// Next Render Pass. | ||
var nextRenderAndSnapshot: RenderingAndSnapshot<RenderingT> = runner.nextRendering() | ||
|
||
if (runtimeConfig.contains(CONFLATE_STALE_RENDERINGS)) { | ||
// Only null will allow us to continue processing actions and conflating stale renderings. | ||
// If this is not null, then we had an Output and we want to send it with the Rendering | ||
// (stale or not). | ||
while (actionResult is ActionApplied<*> && actionResult.output == null) { | ||
// We have more actions we can process, so this rendering is stale. | ||
while (isActive && actionResult is ActionApplied<*> && actionResult.output == null) { | ||
// We may have more actions we can process, this rendering could be stale. | ||
actionResult = runner.processAction(waitForAnAction = false) | ||
|
||
if (!isActive) return@launch | ||
|
||
// If no actions processed, then no new rendering needed. | ||
// If no actions processed, then no new rendering needed. Pass on to UI. | ||
if (actionResult == ActionsExhausted) break | ||
|
||
// Skip rendering if we had unchanged state, keep draining actions. | ||
if (shouldShortCircuitForUnchangedState(actionResult)) continue | ||
|
||
// Make sure the runtime has not been cancelled from runner.processAction() | ||
if (!isActive) return@launch | ||
|
||
nextRenderAndSnapshot = runner.nextRendering() | ||
} | ||
} | ||
|
||
// Pass on to the UI. | ||
// Pass on the rendering to the UI. | ||
renderingsAndSnapshots.value = nextRenderAndSnapshot | ||
// And emit the Output. | ||
|
||
// Emit the Output | ||
sendOutput(actionResult, onOutput) | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new tongue-twister just dropped