nadako / TinkStateSharp

Handle those pesky states, now in C#
https://nadako.github.io/TinkStateSharp/
The Unlicense
40 stars 1 forks source link

Implement granular observability for collection elements #12

Open nadako opened 1 year ago

nadako commented 1 year ago

Basically https://github.com/haxetink/tink_state/issues/49 (which is also implemented in https://github.com/haxetink/tink_state/pull/74, so we can adapt that).

The idea is that if an Observable.Auto/AutoRun is only accessing a specific key from an observable list or dictionary, the recomputation should trigger only if that specific key is changed, not when anything is changed inside the collection.

Example:

var dict = Observable.Dictionary<string, int>();
dict["a"] = 1;
dict["b"] = 1;

Observable.AutoRun(() => Console.WriteLine(dict["a"]));

dict["a"] = 2; // should trigger re-run
dict["b"] = 2; // should NOT trigger re-run