MapSignalMixin#
Kind:
class |
Package: package:signals_core
Class: MapSignalMixin#
A mixin that adds reactive Map methods and operators directly to a Signal.
This mixin delegates all standard Map operations (such as mutations like []=,
clear,
remove, and lookups like containsKey, isEmpty,
keys, values) to the underlying
map value.
Every mutating operation automatically updates the signal and notifies its observers
(by forcing a change notification using force: true).
Simple Example#
class MyMapSignal<K, V> extends Signal<Map<K, V>>
with MapSignalMixin<K, V, Map<K, V>> {
MyMapSignal(super.value);
}
final cart = MyMapSignal<String, int>({'apple': 1});
// Register an effect reacting to cart changes
effect(() {
print('Cart length: ${cart.length}');
});
// Treating it as a standard Map triggers updates automatically!
cart['banana'] = 3; // Prints: Cart length: 2
cart.remove('apple'); // Prints: Cart length: 1
Members of MapSignalMixin#
| Member | Type | Signature | Description |
|---|---|---|---|
| [] | method |
dart V? [](Object? key) |
|
| []= | method |
dart void []=(K key, V value) |
|
| addAll | method |
dart void addAll(Map<K, V> other) |
|
| addEntries | method |
dart void addEntries(Iterable<MapEntry<K, V>> newEntries) |
|
| cast | method |
dart Map<RK, RV> cast() |
|
| clear | method |
dart void clear() |
|
| containsKey | method |
dart bool containsKey(Object? key) |
|
| containsValue | method |
dart bool containsValue(Object? value) |
|
| entries | method |
dart Iterable<MapEntry<K, V>> entries |
|
| forEach | method |
dart void forEach(void Function(K key, V value) action) |
|
| isEmpty | method |
dart bool isEmpty |
|
| isNotEmpty | method |
dart bool isNotEmpty |
|
| keys | method |
dart Iterable |
|
| length | method |
dart int length |
|
| map | method |
dart Map<K2, V2> map(MapEntry<K2, V2> Function(K key, V value) convert) |
|
| putIfAbsent | method |
dart V putIfAbsent(K key, V Function() ifAbsent) |
|
| remove | method |
dart V? remove(Object? key) |
|
| removeWhere | method |
dart void removeWhere(bool Function(K key, V value) test) |
|
| update | method |
dart V update(K key, V Function(V value) update, {V Function()? ifAbsent}) |
|
| updateAll | method |
dart void updateAll(V Function(K key, V value) update) |
|
| values | method |
dart Iterable |
|
| toMap | method |
dart Map<K, V> toMap() |
Snapshot of MapEntries |
References#
The MapSignalMixin type is referenced and used in the following pages:
- MapSignalMixin (signals_flutter/mixins)
- signals_flutter
- MapSignalMixin (signals_core/mixins)
- signals_core
- MapSignalMixin (signals/mixins)
- signals