Replies: 1 comment
-
I sympathize with the concept, but I'm not a fan of duplicating functionality in general. So I'd need something a lot more compelling than even this to want to add it to v2. I will state such a change is very, very likely for v3, though. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recent discussions on possible future design directions for Mithril have suggested there is a desire to reduce the number of lifecycle hooks. From those discussions arose a suggestion to provide the equivalent of the current
onremove
hook by returning a function fromoncreate
.This could be added to the current V2 API in a non-breaking way, and could provide a nicer API for setup/teardown for certain use cases, generally revolving around direct DOM access. For example, to set up a component that automatically resizes a canvas element, one must currently write something like:
3rd party lib integration is often similar:
With a callback returned from
oncreate
, the above examples could be simplified to:and:
Stateful components are no longer needed simply to persist these stateful items that need cleanup.
There are of course other cases where stateful components will still be needed. And the
onremove
hook should of course continue to be supported. In cases where a function is returned fromoncreate
and aonremove
hook exists, I would thinkonremove
should be called last.Beta Was this translation helpful? Give feedback.
All reactions