call method

EffectScope call({
  1. void fn(
    1. EffectScope scope
    )?,
  2. bool detach = false,
  3. List<Object?>? keys,
  4. JoltDebugOption? debug,
})

Creates an effect scope hook for managing effect lifecycles.

An effect scope allows you to group related effects together and dispose them all at once. Useful for component-based architectures.

Parameters:

  • fn: Optional function to execute within the scope context
  • keys: Optional keys for hook memoization
  • debug: Optional debug options

Returns: An EffectScope for managing effect lifecycles

Example:

Widget build(BuildContext context) {
  useEffectScope(fn: (scope) {
    scope.run(() {
      final signal = Signal(0);
      Effect(() => print(signal.value));

      onScopeDispose(() => print('Scope cleaned up'));
    });
  });

  return Text('Component with scoped effects');
}

Implementation

EffectScope call({
  void Function(EffectScope scope)? fn,
  bool detach = false,
  List<Object?>? keys,
  JoltDebugOption? debug,
}) {
  return use(JoltEffectHook(() {
    final scope = EffectScope(detach: detach, debug: debug);
    if (fn != null) {
      scope.run(() => fn(scope));
    }
    return scope;
  }, keys: keys));
}