operator []= method

  1. @override
void operator []=(
  1. K key,
  2. V value
)
override

Associates the key with the given value.

If the key was already in the map, its associated value is changed. Otherwise the key/value pair is added to the map.

Implementation

@override
void operator []=(K key, V value) {
  _context.conditionallyRunInAction(() {
    final oldValue = _map[key];
    var type = 'set';

    if (_hasListeners) {
      if (_map.containsKey(key)) {
        type = 'update';
      } else {
        type = 'add';
      }
    }

    if (!_map.containsKey(key) || value != oldValue) {
      _map[key] = value;
      if (type == 'update') {
        _reportUpdate(key, value, oldValue);
      } else if (type == 'add') {
        _reportAdd(key, value);
      }
      _atom.reportChanged();
    }
  }, _atom);
}