Git Product home page Git Product logo

databinding's Introduction

Databinding Service

Databinding library can be used to set application data and bind them to events when they change. Useful for a heavy data oriented system.

Data on a tree!

ย 

Each node represent a data in this service, so for example the branch "app.settings.audio.music" corresponds to the branch "A.B.H.N", branches can be reached in the tree by nodes, depth or branch ids.

The dot (.) is considered as a node separator in the system, can be changed to any char here

How to use it

To start the databinding service simply create an instance of it

using DataBinding;

var dataBinding = new DataBindingService();

Add data

Call AddData by providing the data type and the a branch, new nodes will be created if nodes of the branch don't exists.

dataBinding.AddData<bool>("app.settings.notifications", true)
           .AddData<bool>("app.settings.notifications.hasSound", true)
           .AddData<bool>("app.settings.sound.music", true);

Binding components

Components bind to a data branch and get notified if the data changes in the system. Implement BindingComponent<T> interface by the specifying the data type which it will bind to.

public class SampleBindingComponent : BindingComponent<bool>
{
    public void OnValueChanged(string branch, bool value)
    {
        // Do stuff with the new data
    }
}

Binding data to components

Call Bind<T>(branch, instance) by specifying the data type, the data branch and the binding component instance.

var sampleBindingComponent = new SampleBindingComponent();

dataBinding.Bind<bool>("app.settings.sound.music", sampleBindingComponent);

Get and modify data

Call GetData<T>(string branch) to get an object of type Data<T> and access its value.

var musicData = dataBinding.GetData<bool>("app.settings.sound.music");
var isMusicEnabled = musicData.value;

// Change data and reassign
isMusicEnabled = !isMusicEnabled;
musicData.value = isMusicEnabled;

Reassigning the value will notify automatically components bind to this data. To manually notify components, on the Data<T> object call NotifyComponents.

musicData.NotifyComponents()

Tests

To better understand the system and have a quick dive in the codebase have a look at the unit tests in the project.

Useful methods

  • GetData<T>(string nodeId, int treeDepth) if you know the node and the data depth in the tree
  • ContainsNode(string branch)
  • ExtractNode(string branch) will return a node object

databinding's People

Contributors

adizhavo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

bubdm

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.