atomFamily<A extends Atom, Arg> function
A Function(Arg arg)
atomFamily<A extends Atom, Arg>(
- A create(
- Arg arg
Create a family factory function, for indexing similar atoms with the
Arg
type.
final userAtom = atomFamily((int id) => atom((get) => get(listOfUsers).getById(id)));
// To get an atom that points to user with id 123
final user123Atom = userAtom(123);
Implementation
A Function(Arg arg) atomFamily<A extends Atom, Arg>(
A Function(Arg arg) create,
) {
final atoms = HashMap<Arg, A>();
return (arg) => atoms[arg] ??= create(arg);
}