@epikodelabs/streamix / src/public-api / scope
Function: scope()
Call Signature
scope<
T>(state,options?):ScopeReturn<ScopeOf<T>>
Defined in: projects/libraries/streamix/src/lib/atoms/scope.ts:752
Creates an execution boundary to encapsulate, track, and bulk-dispose reactive units. Atoms created inside an analog scope defer public broadcasts to the scheduler instead of notifying subscribers synchronously.
The returned object is a Proxy: reading an exported atom returns its current value, and writing to an exported atom forwards the value to atom.next(). Use scope.at('key') or scope.at.key to reach the underlying atom when you need to subscribe, dispose, or call other atom methods directly.
Object form — primitives are wrapped in atoms, nested plain objects become nested scopes, and functions become derived expressions:
const app = scope<AppShape>({
query: '',
count: (self) => self.query.length,
});Factory form — useful for setup-time side effects like provide():
const app = scope<AppShape>(() => {
provide(Config, () => ({ apiUrl: '/api' }));
return { apiUrl: () => inject(Config).apiUrl };
});Type Parameters
T
T extends Record<string, any>
Parameters
state
DefinedInput<T>
options?
mode?
"discrete" | "analog"
Returns
ScopeReturn<ScopeOf<T>>
Call Signature
scope<
T>(factory,options?):ScopeReturn<ScopeOf<T>>
Defined in: projects/libraries/streamix/src/lib/atoms/scope.ts:757
Creates an execution boundary to encapsulate, track, and bulk-dispose reactive units. Atoms created inside an analog scope defer public broadcasts to the scheduler instead of notifying subscribers synchronously.
The returned object is a Proxy: reading an exported atom returns its current value, and writing to an exported atom forwards the value to atom.next(). Use scope.at('key') or scope.at.key to reach the underlying atom when you need to subscribe, dispose, or call other atom methods directly.
Object form — primitives are wrapped in atoms, nested plain objects become nested scopes, and functions become derived expressions:
const app = scope<AppShape>({
query: '',
count: (self) => self.query.length,
});Factory form — useful for setup-time side effects like provide():
const app = scope<AppShape>(() => {
provide(Config, () => ({ apiUrl: '/api' }));
return { apiUrl: () => inject(Config).apiUrl };
});Type Parameters
T
T extends Record<string, any>
Parameters
factory
() => DefinedInput<T>
options?
mode?
"discrete" | "analog"
Returns
ScopeReturn<ScopeOf<T>>