Skip to content

CreateScopes type

Home > @rimitive/view > CreateScopes

Public scope API for managing element lifecycles and cleanup.

Signature:

export type CreateScopes = {
disposeScope: <TElement = object>(scope: RenderScope<TElement>) => void;
createElementScope: <TElement extends object = object>(element: TElement, fn: () => void) => RenderScope<TElement> | null;
scopedEffect: (fn: () => void | (() => void)) => () => void;
onCleanup: (cleanup: () => void) => void;
getElementScope: <TElement extends object>(element: TElement) => RenderScope<TElement> | undefined;
};

References: RenderScope

import { createScopes, type CreateScopes } from '@rimitive/view/deps/scope';
const scopes: CreateScopes = createScopes({ baseEffect: effect });
// Use in element creation
const scope = scopes.createElementScope(element, () => {
scopes.scopedEffect(() => {
console.log('Reactive effect');
});
scopes.onCleanup(() => {
console.log('Cleanup when element is removed');
});
});