Whisk is a micro-framework for tracking and updating computational dependencies.
PM> Install-Package Whisk
This C# snippet shows how to create mutable values, subscribe to changes, and make changes atomically:
// Create mutable containers for first and last name.
var first = D.Mutable("Reginald");
var last = D.Mutable("Dwight");
// Create a full-name dependency that will track the first and last name.
var full = D.Pure(D.All(first, last), () => $"{first.Value} {last.Value}");
// Watch the full name and print all values to the console.
var subscription = full.Watch(Console.WriteLine);
// Atomically update the first and last name at the same time.
D.Set(D.Value(first, "Elton"), D.Value(last, "John"));
// Stop printing the full name to console.
subscription.Dispose();
The expected output is:
Reginald Dwight
Elton John
-
Create a constant:
var maxHumanLifeSpan = D.Constant(TimeSpan.FromYears(126)); var minMarginalTaxRate = D.Constant(0.01);
-
Bind to a property change event:
var form = new Form(); var text = D.Property(form, f => f.Text).Changed((f, e) => f.TextChanged += e, (f, e) => f.TextChanged += e);
-
Bind to an
INotifyPropertyChaged
object.var obj = new MyReactiveObject(); var name = D.PropertyChanged(obj, o => o.Name);