@gluonjs/reactivity / packages/reactivity/src / onScopeDispose
Function: onScopeDispose()
onScopeDispose(
cleanup):boolean
Parameters
cleanup
() => void
Returns
boolean
Example
Register teardown beside the effect or resource it belongs to so stopping the active scope releases both:
import {
EffectScope,
effect,
effectScope,
getCurrentScope,
onScopeDispose,
ref,
type EffectScopeOptions,
} from '@gluonjs/reactivity';
const options: EffectScopeOptions = {
detached: true,
onError: ({ error }) => console.error(error),
};
const scope: EffectScope = effectScope(options);
const count = ref(0);
scope.run(() => {
console.log(getCurrentScope() === scope);
effect(() => console.log(count.value));
onScopeDispose(() => console.log('scope disposed'));
});
count.value = 1;
scope.stop();