otac0n / Whisk

Whisk is a micro-framework for tracking and updating computational dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Whisk

Whisk is a micro-framework for tracking and updating computational dependencies.

MIT Licensed Get it on NuGet

Appveyor Build Test Coverage Pre-release packages available

Getting Started

PM> Install-Package Whisk

Example

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

Integration

Constant

  • Create a constant:

    var maxHumanLifeSpan = D.Constant(TimeSpan.FromYears(126));
    var minMarginalTaxRate = D.Constant(0.01);

Property Changed

  • 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);
    

About

Whisk is a micro-framework for tracking and updating computational dependencies.

License:MIT License


Languages

Language:C# 100.0%