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.
Add support for
on-change
on a cursor to return a promise. Anyone can start an update transaction withstart-transaction
. Any updates to the cursor in between that call and a subsequent call toend-transaction
passing the transaction obtained fromstart-transaction
may trigger one or moreon-change
handlers. Those handlers may rely on asynchronous calls. If they do, they can now return a promise, which they resolve when their asynchronous behaviour is done. All promises returned by theon-change
handlers are collected on all running transactions and the call toend-transaction
returns a promise waiting for all of them to finish (using bluebird's.all
). If no change handlers were registered or no promises were returned theend-transaction
call will return a resolved promise.This is useful in multiple scenarios and simplifies dealing with asynchronous calls in state observers. For instance, using this, Reflex can wait for even asynchronous change handlers to finish what they are doing before rendering server side. In the same way, application initialisation can trigger an async on-change with a state update and Reflex will wait until it is finished before rendering (no need for an explicit
done
callback instart
or route initialisation).To Do