Open trusktr opened 6 months ago
this.createEffect() will make an effect that is conveniently stopped in disconnectedCallback. This is useful for creating effects in connectedCallback and then not having to use createRoot and disconnectedCallback to stop them.
this.createEffect()
disconnectedCallback
connectedCallback
createRoot
Currently:
connectedCallback() { super.connectedCallback() createRoot(dispose => { this.dispose = dispose createEffect(() => { // ... onCleanup(() => {...}) }) }) } disconnectedCallback() { super.disconnectedCallback() this.dispose() }
Using this.createEffect:
this.createEffect
connectedCallback() { super.connectedCallback() this.createEffect(() => { // ... onCleanup(() => {...}) }) }
this.createEffect()
will make an effect that is conveniently stopped indisconnectedCallback
. This is useful for creating effects inconnectedCallback
and then not having to usecreateRoot
anddisconnectedCallback
to stop them.Currently:
Using
this.createEffect
: