stage0 icon indicating copy to clipboard operation
stage0 copied to clipboard

Lifecycle events - Any destroy/unmount/componentWillUmmount equivalent event?

Open kenfoo opened this issue 5 years ago • 1 comments

Often times we need to perform some cleanup before a node is removed from DOM, such as clearing timeouts, etc.

Are there any such callbacks/events that will be called prior to unmounting?

Skimming through reconcile(), I don't see anywhere the presence of such logic before .removeChild() is called.

kenfoo avatar Sep 30 '19 02:09 kenfoo

Yep, reconcile doesn't have unmount callback, and was designed without any lifecycle managing in mind.

The problems that I see with implementing unmount cb:

  • It will affect performance on clearing and removing nodes.
  • For lifecycles to work properly, all system need some way to propagate these events throughout the tree up and down, so you don't need to carry unmount housekeeping on each reconcile call level. Like if you have rendered list of components that have array inside each/some of them. This is the point where Virtual DOM systems fits really nice.

I have some ideas on how to redesign API to fit such cases better. Will keep this issue open and update once will be implemented.

Freak613 avatar Sep 30 '19 04:09 Freak613