Git Product home page Git Product logo

kabash's Introduction

Kabash Observables

travis nuget

An observable library for multi-way data binding.

Basics

var observable = new Observable<string>();
observable.ValueChanged += OnValueChanged;
observable.Value = "Hello World";

// Also supports implicit conversion...
var observable = (Observable<string>)"Hello World";

private void OnValueChanged(IObservable<string> sender, ObservedValueChangedEventArgs<string> e)
{
    Console.WriteLine(e.PreviousValue);
    Console.WriteLine(e.CurrentValue);
}

Mirroring For Data-Binding

You can mirror another observable to change the value immediately when the mirrored observable changes. You can remove this binding via UnMirror.

var a = new Observable<float>();
a.Value = 10;

var b = new Observable<float>();
b.Mirror(a);

a.Value = 20;

// Both equal 20...
Assert.AreEqual(a.Value, b.Value);

When Queries

You can invoke callbacks upon the observable value reaching a specific query. These will be invoked immediately if the query passes matches. These callbacks will remain for the lifetime of the observable unless removed with RemoveQuery.

var a = new Observable<float>();
a.When(v => v == 10, OnWhenCriteriaMet);
a.Value = 5;

// Callback triggered...
a.Value = 10;

private void OnWhenCriteriaMet(IObservable<float> sender, ObservedCriteriaMetEventArgs<float> e)
{
    Console.WriteLine(sender.Value);
}

IOC Compliant

The library is IOC compliant. You can implement the IObservableFactory for providing a means to resolve an unknown observable at runtime. If in Unity, you will run into AOT issues if you go this route. The solution is to ensure that you reference the implemented signature at least once so it gets compiled.

ObservableList

Use the ObservabeList to get callbacks when elements are added, removed, and modifed via this[index].

var listA = new ObservableList<string>();
var listB = new ObservableList<string>();

// Mirror everyting that happens with listB.
listA.Mirror(listB);
listB.Add("Hello World");

// Writes "Hello World"...
Console.WriteLine(listA[0]);

// True because the same element is on both lists...
Assert.AreEqual(listA[0], listB[0]);

kabash's People

Watchers

Devon Klompmaker avatar James Cloos avatar Bill Salak avatar Bill McCaffrey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.