EffectScopeImpl constructor

EffectScopeImpl({
  1. bool? detach,
  2. JoltDebugFn? onDebug,
})

Creates a new effect scope.

Parameters:

  • detach: Whether to detach this scope from its parent scope. If true, the scope will not be automatically disposed when its parent is disposed. Defaults to false.
  • onDebug: Optional debug callback for reactive system debugging

The scope is automatically linked to its parent scope (if any) unless detach is true. Use run to execute code within the scope context.

Example:

final scope = EffectScope()
  ..run(() {
    final signal = Signal(0);
    Effect(() => print(signal.value));

    // Register cleanup function
    onScopeDispose(() => print('Scope disposed'));
  });

Implementation

EffectScopeImpl({bool? detach, JoltDebugFn? onDebug})
    : super(flags: ReactiveFlags.none) {
  JoltDebug.create(this, onDebug);
  if (!(detach ?? false)) {
    final prevSub = getActiveSub();
    if (prevSub != null) {
      link(this, prevSub, 0);
    }
  }
}