-
-
Notifications
You must be signed in to change notification settings - Fork 922
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
feat: Add ComponentTreeRoot.lifecycleEventsProcessed future #3308
feat: Add ComponentTreeRoot.lifecycleEventsProcessed future #3308
Conversation
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.
Oh this is very cool! I wonder if could in fact replace the game.ready()
method that we have for our tests.
…e queue is processed
The big difference is that So, you could use the new future in tests, but you'd also have to kick off the process somehow. |
The |
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.
Overall it looks good, very good dartdocs!
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.
Lgtm! Just one minor formatting issue left
Adds a future that will complete once all lifecycle events have been processed. If there are no lifecycle events to be processed (`hasLifecycleEvents` is `false`), then this future returns immediately. This is useful when you modify the component tree (by adding, moving or removing a component) and you want to make sure you react to the changed state, not the current one. Remember, methods like `Component.add` don't act immediately and instead enqueue their action. This action also cannot be awaited with something like `await world.add(something)` since that future completes _before_ the lifecycle events are processed. Example usage: ```dart player.inventory.addAll(enemy.inventory.children); await game.lifecycleEventsProcessed; updateUi(player.inventory); ```
Description
Adds a future that will complete once all lifecycle events have been processed.
If there are no lifecycle events to be processed (
hasLifecycleEvents
isfalse
), then this future returns immediately.This is useful when you modify the component tree (by adding, moving or removing a component) and you want to make sure you react to the changed state, not the current one.
Remember, methods like
Component.add
don't act immediately and instead enqueue their action. This action also cannot be awaited with something likeawait world.add(something)
since that future completes before the lifecycle events are processed.Example usage:
Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Related Issues
Discussed here: https://discord.com/channels/509714518008528896/1285583996842934348