LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

Type: SetSignal

API reference and details for SetSignal from signals.dart.

SetSignal#

Kind: class & function  |  Package: package:signals_core

Class: SetSignal#

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

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

Additionally, SetSignal defines convenient operators:

  • << injects/adds all items from another set into the current set.
  • & forks/unions the set with another set into a new SetSignal.
  • | pipes/unions the set with another signal holding an iterable into a new SetSignal.

Example Usage#

import 'package:signals/signals.dart';

void main() {
  final numbers = setSignal<int>({1, 2, 3});

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

  // Standard mutation (triggers updates)
  numbers.add(4); // Prints: "Set content: {1, 2, 3, 4}, Length: 4"

  // Removing an element (triggers updates)
  numbers.remove(1); // Prints: "Set content: {2, 3, 4}, Length: 3"

  // Set intersection (reactive query)
  final common = numbers.intersection({3, 4, 5});
  print(common); // Prints: {3, 4}
}
Mutating the collection directly calls the reactive set() routine under the hood automatically. You do not need to assign numbers.value = ... manually!

Members of SetSignal#

Member Type Signature Description
SetSignal constructor dart SetSignal(super.value, {SetSignalOptions ? options, @Deprecated('Use options: SetSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: SetSignalOptions(name: ...) instead') String? debugLabel}) Creates a SetSignal with the given value.
<< method dart SetSignal <<(Set other) Inject: Update current signal value with iterable
& method dart SetSignal &(Set other) Fork: create a new signal with value is the concatenation of source signal and iterable parameter
** ** method dart SetSignal
== method dart bool ==(Object other)
hashCode method dart int hashCode

Function: setSignal#

SetSignal<T> setSignal(Set<T> list, {SetSignalOptions<T>? options, @Deprecated('Use options: SetSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: SetSignalOptions(name: ...) instead') String? debugLabel})

Creates a SetSignal initialized with the provided set.

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

import 'package:signals/signals.dart';

final mySet = setSignal({1, 2, 3});

References#

The SetSignal type is referenced and used in the following pages: