-
var atom = Atom(Set("A", "B", "C"));
atom.Change += value => Console.WriteLine(string.Join(',', value));
atom.Swap(old => old.Add("D"));
atom.Swap(old => old.Add("E"));
atom.Swap(old => old);
Actually, I would like to use atom in the following context: Now the problem is that the I would like to have |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The alternative would be to use var atom = AtomHashMap(("A", unit), ("B", unit), ("C", unit));
atom.Change += value => Console.WriteLine(string.Join(',', value.Changes));
atom.AddOrUpdate("D", default);
atom.AddOrUpdate("E", default);
atom.AddOrUpdate("E", default); // no event thrown It can properly track changes to individual keys, and knows how to produce patches of what's changed. |
Beta Was this translation helpful? Give feedback.
-
No, you're right, I've just checked the code and it's not doing any equality checks (reference or otherwise), it's just announcing every update. I'll convert this to a bug, but I probably won't get to it super quickly unfortunately. |
Beta Was this translation helpful? Give feedback.
Atom
uses references internally (and reference equality to check for changes).Set
is a value-type and therefore is boxed when stored in anAtom
, this will generate a new box every time. You could use theObservable
extensions forAtom
to keep a window of the last and current update, then use structural equality to check for changes.The alternative would be to use
AtomHashMap<string, Unit>
(sorry, I haven't got around to writingAtomHashSet
andAtomSet
yet).