addAtom<T> method Null safety

Atom<T>? addAtom<T>(
  1. Atom<T> atom
)

Adds an Atom to the store. atom is the Atom to be added to the store.

Returns the Atom added to the store if no Atom with the same key exists, otherwise returns null.

Implementation

Atom<T>? addAtom<T>(Atom<T> atom) {
  if (_atoms.containsKey(atom.key)) {
    return null;
  }

  return _atoms.putIfAbsent(atom.key, () => atom) as Atom<T>;
}