LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

ListSignal

A reactive Signal that holds a **List** and implements the **List** interface.

A reactive Signal that holds a List and implements the List interface.

ListSignal lets you listen to changes on a list reactively and mutate it directly using standard list operations (like add, addAll, remove, operators [] and []=, etc.). Any mutations automatically trigger reactive updates to all active listeners (e.g., inside an effect or computed).

Additionally, ListSignal defines convenient operators:

  • << injects/adds all items from an iterable into the list.
  • & forks/concatenates the list with an iterable into a new ListSignal.
  • | pipes/concatenates the list with another signal holding an iterable into a new ListSignal.

Example Usage#

import 'package:signals/signals.dart';

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

  effect(() {
    print('List content: $numbers, Length: ${numbers.length}');
  }); // Prints: "List content: [1, 2, 3], Length: 3"

  // Standard mutation (triggers updates)
  numbers.add(4); // Prints: "List content: [1, 2, 3, 4], Length: 4"

  // Update via index operator (triggers updates)
  numbers[0] = 10; // Prints: "List content: [10, 2, 3, 4], Length: 4"

  // Injection operator (triggers updates)
  numbers << [5, 6]; // Prints: "List content: [10, 2, 3, 4, 5, 6], Length: 6"
}
Mutating the collection directly calls the reactive set() routine under the hood automatically. You do not need to assign numbers.value = ... manually!

Constructors#

View Constructors
ListSignal(super.value, {ListSignalOptions<E>? options, @Deprecated('Use options: ListSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: ListSignalOptions(name: ...) instead') String? debugLabel})

Creates a ListSignal with the given value.

Methods#

View Methods
ListSignal<E> <<(Iterable<E> other)

Inject: Update current signal value with iterable

ListSignal<E> &(Iterable<E> other)

Fork: create a new signal which value is the concatenation of source signal and iterable parameter

ListSignal<E> |(Signal<Iterable<E>> other)

Pipe: create a new signal by sending value from source to other

bool ==(Object other)
int hashCode

listSignal#

Creates a ListSignal initialized with the provided list.

This is a convenience helper function for creating reactive list signals.

import 'package:signals/signals.dart';

final list = listSignal([1, 2, 3]);