LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

MapSignal

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

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

MapSignal lets you listen to changes on a map reactively and mutate it directly using standard map operations (like adding/modifying keys with operator []=, addAll, remove, clear, etc.). Any mutations automatically trigger reactive updates to all active listeners (e.g., inside an effect or computed).

Additionally, MapSignal defines convenient operators:

  • << injects/adds all entries from another map into the current map.
  • & forks/concatenates the map with another map into a new MapSignal.
  • | pipes/concatenates the map with another signal holding a map into a new MapSignal.

Example Usage#

import 'package:signals/signals.dart';

void main() {
  final settings = mapSignal<String, dynamic>({
    'theme': 'light',
    'notifications': true,
  });

  effect(() {
    print('Theme is currently: ${settings['theme']}');
  }); // Prints: "Theme is currently: light"

  // Update key/value pair directly (triggers updates)
  settings['theme'] = 'dark'; // Prints: "Theme is currently: dark"

  // Expose standard Map methods
  settings.remove('notifications');
}
Mutating the collection directly calls the reactive set() routine under the hood automatically. You do not need to assign settings.value = ... manually!

Constructors#

View Constructors
MapSignal(super.value, {MapSignalOptions<K, V>? options, @Deprecated('Use options: MapSignalOptions(autoDispose: ...) instead') bool? autoDispose, @Deprecated('Use options: MapSignalOptions(name: ...) instead') String? debugLabel})

Creates a MapSignal with the given value.

Methods#

View Methods
MapSignal<K, V> <<(Map<K, V> other)

Inject: Update current signal value with iterable

MapSignal<K, V> &(Map<K, V> other)

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

MapSignal<K, V> |(Signal<Map<K, V>> other)

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

bool ==(Object other)
int hashCode

mapSignal#

Creates a MapSignal initialized with the provided map.

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

import 'package:signals/signals.dart';

final settings = mapSignal({'theme': 'dark'});