LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

Type: SetSignalMixin

API reference and details for SetSignalMixin from signals.dart.

SetSignalMixin#

Kind: class  |  Package: package:signals_core

Class: SetSignalMixin#

A mixin that adds reactive Set methods and operations to a Signal holding a Set value.

This mixin delegates all standard Set operations (such as mutations like add, remove, addAll, removeAll, retainAll, and clear) to the underlying set, while ensuring that any reads register a dependency and any mutations automatically trigger reactive updates.

This mixin only works with signals that have a value type extending Set.

Example Usage#

import 'package:signals/signals.dart';

class MySetSignal extends Signal<Set<int>>
    with IterableSignalMixin<int, Set<int>>, SetSignalMixin<int, Set<int>> {
  MySetSignal(super.internalValue);
}

void main() {
  final numbers = MySetSignal({1, 2, 3});

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

  // Adding an element (automatically calls set() and triggers updates)
  numbers.add(4); // Prints: "Elements: {1, 2, 3, 4}, Length: 4"

  // Removing an element (triggers updates)
  numbers.remove(1); // Prints: "Elements: {2, 3, 4}, Length: 3"
}
Since mutations on SetSignalMixin notify listeners automatically, you do not need to assign numbers.value = ... to force updates. Methods like add, addAll, and remove take care of notification.

Members of SetSignalMixin#

MemberTypeSignatureDescription
addmethoddart bool add(E value)
addAllmethoddart void addAll(Iterable elements)
castmethoddart Set cast()
clearmethoddart void clear()
containsAllmethoddart bool containsAll(Iterable<Object?> other)
differencemethoddart Set difference(Set<Object?> other)
intersectionmethoddart Set intersection(Set<Object?> other)
lookupmethoddart E? lookup(Object? object)
removemethoddart bool remove(Object? value)
removeAllmethoddart void removeAll(Iterable<Object?> elements)
removeWheremethoddart void removeWhere(bool Function(E element) test)
retainAllmethoddart void retainAll(Iterable<Object?> elements)
retainWheremethoddart void retainWhere(bool Function(E element) test)
unionmethoddart Set union(Set other)

References#

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