LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

IterableSignal

A reactive Signal that holds an Iterable and implements the Iterable interface.

A reactive Signal that holds an Iterable and implements the Iterable interface.

IterableSignal allows you to listen to changes on an iterable collection reactively. It exposes all standard Iterable properties and methods (like length, first, map, where, etc.) directly on the signal itself. Calling these methods inside a reactive context (like an effect or computed block) will automatically track them as dependencies.

Example Usage#

import 'package:signals/signals.dart';

void main() {
  final items = iterableSignal<int>([1, 2, 3]);

  effect(() {
    print('Items length: ${items.length}, First: ${items.first}');
  }); // Prints: "Items length: 3, First: 1"

  // Update the signal by assigning a new iterable
  items.value = [10, 20, 30, 40]; // Prints: "Items length: 4, First: 10"
}
Direct mutation of the items inside the iterable will NOT trigger updates. To reactively mutate collections, use specialized signals like ListSignal, SetSignal, or MapSignal.

Constructors#

View Constructors
IterableSignal(super.value, {IterableSignalOptions? options, @Deprecated('Use options: IterableSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: IterableSignalOptions(name: ...) instead') String? debugLabel})

Creates a IterableSignal with the given value.

Methods#

View Methods
bool ==(Object other)
int hashCode

iterableSignal#

Creates an IterableSignal holding the provided iterable.

This is a convenience function that instantiates an IterableSignal, which delegates all standard Iterable operations reactively and tracks changes.

Example Usage#

import 'package:signals/signals.dart';

final s = iterableSignal([1, 2, 3]);
print(s.length); // 3