Vize

disposal-scope

Stable error code reported when one or more owned cleanups fail.

Package @vizejs/composable/disposal-scope
Own the source vize lib pull composable:disposal-scope
Runtime exports DISPOSAL_ERROR_CODE, DisposalError, createDisposalScope
Gzip budget 2048 B

Usage

import { DISPOSAL_ERROR_CODE, DisposalError, createDisposalScope } from "@vizejs/composable/disposal-scope";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
createDisposalScope lifecycle experimental safe not-applicable caller, reactive-scope web, server, worker, native, desktop, terminal — tryOnScopeDispose

API

DISPOSAL_ERROR_CODE

Stable error code reported when one or more owned cleanups fail.

const DISPOSAL_ERROR_CODE

DisposalError

Aggregate failure produced after every owned cleanup has been attempted.

class DisposalError

createDisposalScope

Create an explicit, deterministic cleanup owner. The owner is runtime-neutral and performs no browser-global access. By default it joins an active Vue reactive scope; when no scope exists, or scope is disabled, the caller must invoke dispose(). Cleanups are synchronous by contract so disposal completes before the owner releases its records.

function createDisposalScope(options: CreateDisposalScopeOptions = {}): DisposalScope

Types

CleanupRegistration

Handle for removing one cleanup from its owner before disposal.

Member Type Description
active boolean Whether this registration is still retained by its owner.
unregister () => boolean Release the cleanup without running it.

CreateDisposalScopeOptions

Options for createDisposalScope.

Member Type Description
scope? boolean Dispose the owner with the active Vue reactive scope when one exists. Outside a reactive scope, ownership remains entirely with the caller.

DisposalScope

Explicit owner for a deterministic group of cleanup operations.

Member Type Description
disposed boolean Whether disposal has started or completed.
size number Number of active cleanup registrations currently retained.
add <Cleanup extends () => unknown>( cleanup: [ReturnType<Cleanup>] extends [never] ? Cleanup : ReturnType<Cleanup> extends PromiseLike<unknown> ? never : Cleanup, ) => CleanupRegistration Register one cleanup. Active registrations run in last-in, first-out order. After disposal, registration runs the cleanup immediately and returns an inactive handle; a late failure is wrapped in DisposalError.
child () => DisposalScope Create a child whose lifetime cannot outlive this owner. Disposing the child early unregisters it from the parent. Disposing the parent disposes the child in normal LIFO order.
dispose () => void Run every active cleanup in last-in, first-out order exactly once. Reentrant and late registrations run immediately. All cleanups are attempted even when some fail. Repeated calls after successful or failed disposal do nothing.