-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[Suggestion] Notify added observer if observable was triggered. #13565
Conversation
This is done to avoid the pattern of adding an observer after checking if the state requires that. As an example let's take the scene's onReadyObservable which has a simple state - it will only notify once when the scene is ready. If a new observer will be added after the observable was triggered (and has notified existing observers) it will not be possible to trigger new observers that were added to is. If `notifyIfTriggered` is set to true and the observable has already triggered it will automatically trigger newly added observers whenever they are added. It's also recommended to add that to onDispose observables, which are the same. A different solution would be to define an onObserverAdded function, but that would require setting this function to every observable that requires it. Instead - this is a more generic solution.
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/13565/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/13565/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/13565/merge#BCU1XR#0 |
It's a breaking change, so I'm not sure we should update our code to use the new feature (although, having the new feature is great!). For the |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Thanks for the review :-) The scene onReady is actually doing roughly that under the hood, so it is not entirely a breaking change. The only difference is at what point would the observer be triggered. |
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.
Maybe we could have a reset functionnality in ?
I was thinking in Texture, onLoaded is called once and we keep the value until somebody calls updateURL for instance ?
This grew a bit bigger than expected. Adding this feature has surfaced memory leaks that we had (mainly undisposed objects and uncleared observables). |
This is done to avoid the pattern of adding an observer after checking if the state requires that.
As an example let's take the scene's onReadyObservable which has a simple state - it will only notify once when the scene is ready. If a new observer will be added after the observable was triggered (and has notified existing observers) it will not be possible to trigger new observers that were added to is.
If
notifyIfTriggered
is set to true and the observable has already triggered it will automatically trigger newly added observers whenever they are added.It's also recommended to add that to onDispose observables, which are the same.
A different solution would be to define an onObserverAdded function, but that would require setting this function to every observable that requires it. Instead - this is a more generic solution.