Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

[core] Similar to tick late-tick etc., also offer mount and unmount (or similar) #48

Open
2 tasks
hmans opened this issue Jan 31, 2021 · 2 comments
Open
2 tasks
Labels
enhancement New feature or request
Milestone

Comments

@hmans
Copy link
Owner

hmans commented Jan 31, 2021

We currently have a convenient way of running code in every frame, but if we want to run code when an element appears (or disappears), we currently have to drop into the imperative layer or, worse, build our own class extending ThreeElement and overloading mountedCallback and friends.

It would be nice if we could add code that is run when the element appears (and disappears) by setting a property or attribute, just like we can do with ticker events.

These new attributes could be named something like mount and unmount, or appear and disappear, or something similar.

There's an opportunity here to make them real DOM events, but I think that would be a mistake; if there's a large number of objects appearing or disappearing, it would have a significant impact on performance (and memory/GC). So, just like the ticker callbacks, these need to run through an EventEmitter, which means we'll have to add one of those guys to BaseElement.

Checklist:

  • Decide on a good name for these
  • Implement them :-)
@hmans hmans added this to the 0.4 milestone Jan 31, 2021
@hmans hmans added the enhancement New feature or request label Jan 31, 2021
@CodyJasonBennett
Copy link
Contributor

Not sure exactly what mount implies but appear can be misleading if objects do not leave view.

@hmans
Copy link
Owner Author

hmans commented Feb 2, 2021

I'm currently using the term "mount" to describe the point at which a ThreeElement is not only connected (in the web components sense), but has also initialized everything its Three.js-specific stuff, which typically happens within a microtask enqueued to be executed after all the elements are finished connecting, so also calling this event "mount" or "mounted" would allow us to continue using that terminology. (Same thing for "remove", which I specifically did not call "unmount" on purpose, because at the point that it is run, the element itself has already been disconnected.)

@hmans hmans changed the title Similar to tick late-tick etc., also offer mount and unmount (or similar) [core] Similar to tick late-tick etc., also offer mount and unmount (or similar) Feb 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants