-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Proposing:
-
this.afterElement(callback?)- likethis.after(...), but only executes when the passed value (the element) changes (loose inequality), passing the new element. Can be called without arguments to return aPromisethat awaits an element change (and returns the new element). -
this.cleanupElement(callback?)- likethis.after(...), but only executes when the passed value (the element) changes (loose inequality), passing the old element. The callback can also be called onthis.cleanup(...)(but the callback only ever gets executed once). Can be called without arguments to return aPromisethat awaits an element change (and returns the old element). -
this.scheduleEach(callback)- likethis.schedule(...), but executes the callback before each render. -
this.afterEach(callback)- likethis.after(...), but executes the callback after each render. -
this.afterEachElement(callback)- likethis.afterEach(...), but only executes when the passed value (the element) changes (loose inequality), passing the new element. -
this.cleanupEachElement(callback)- likethis.afterEach(...), but only executes when the the passed value (the element) changes (loose inequality), passing the old element. The callback also gets called onthis.cleanup(...).
Note that the last four can just be implemented à la requestAnimationFrame, but they still save a few line of code and are a bit easier to read (plus it's nice to have symmetry in the API).
These proposed functions can be implemented in userspace with an injectHelpers(this) or something similar, but they can be hard to get right, and I think they are useful enough to be included in Crank itself.
afterEachElement and cleanupEachElement in particular are useful for managing element-based state like ResizeObserver more easily.