operator [] method

  1. @override
SunnyObservableList<L>? operator [](
  1. Object? key
)
override

The value for the given key, or null if key is not in the map.

Some maps allow null as a value. For those maps, a lookup using this operator cannot distinguish between a key not being in the map, and the key being there with a null value. Methods like containsKey or putIfAbsent can be used if the distinction is important.

Implementation

@override
SunnyObservableList<L>? operator [](Object? key) {
  final k = key as K?;
  return putIfAbsent(k, () {
    final list = SunnyObservableList<L>(debugLabel: "$debugLabel[$key]", diffEquality: listDiffDelegator ?? DiffEquality());
    addDisposer(list.changeStream.listen((changes) {
      _log.fine("Found change to mapList - ${changes.length}");
      changeController.add(newBuilder()..change(k, list));
    }).cancel);
    return list;
  });
}