Manage the preview's rerenders using events#310
Manage the preview's rerenders using events#310sophiedeziel wants to merge 2 commits intodevelopfrom
Conversation
|
Visit the preview URL for this PR (updated for commit 9de20ff): https://gcode-preview--pr310-manage-renders-and-e-569o0jmk.web.app (expires Wed, 08 Oct 2025 03:41:47 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 59bd114ae4847b32c2bba0b68620b9069a3e3531 |
4bf601b to
226945a
Compare
226945a to
4b41806
Compare
| this.eventsDispatcher.addEventListener(SceneManagerEvent.ANIMATION_COMPLETE, () => { | ||
| this.setRerenderListeners(); | ||
| }); |
There was a problem hiding this comment.
That's the key to re-render automatically on changes. This is setting listeners on all properties that we want to see reflected right away on the scene.
| const rerenderDebounce = 100; | ||
| this.eventsDispatcher.addEventListener(eventsRequiringRerender, () => { | ||
| if (this._renderTimeout) clearTimeout(this._renderTimeout); | ||
| this._renderTimeout = setTimeout(() => { | ||
| this.render(); | ||
| }, rerenderDebounce); | ||
| }); |
There was a problem hiding this comment.
debounced event listeners to re-render! ✨ magical ✨
| 'error', | ||
| { | ||
| argsIgnorePattern: '^_', | ||
| ignoreRestSiblings: true |
There was a problem hiding this comment.
That's how I got rid of the es-lint disable comments when defining a class properties without using them in the constructor. Typescript implicitly uses Rest to assign the values, if I understood correctly.
Closes #236
Summary
In order to have the library perform the renders whenever needed, and without the client's intervention (✨ magical ✨), I removed the public
.renderfunction from the main class, the calls from the demo app, and worked from there to have re-renders performed automatically on any setting change.I had trouble assigning the default and initial values without triggering 1000 initial renders. I realized that it would work really well with a debounce and an event listener that only starts listening after the initial setup.
So I introduced a whole events dispatcher that clients can use!
Example:
I did not add the ability to remove a listener yet, I can do it separately or as part of this.
Key changes
.addEventListenerthat can listen to many different events from the lib.SceneManagerfrom simple propertied to_prefixed with getters/setters. It makes the class very long and verbose, but at least they're all consistent!initpreset, we can see them as presets for the UI, that is then applied to the preview.WIP