Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
/ ReaktioJS Public archive

Reaktio.js is a small library which allows you to create a value that can be observed asynchronously.

Notifications You must be signed in to change notification settings

Jarzka/ReaktioJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Reaktio.js is a small library which allows you to create a value that can be observed. If the value is changed, for whatever reason, all observers are notified asynchronously. Observer can be a function or another value which is updated.

Example code:

var a = createReactiveValue(2);
var b = createReactiveValue(1);
var c = createReactiveValue(null);

// We want c to depend on both a and b. If either a or b change, c should automatically recalculate it's value
makeReaction(c, [a, b], (c, [a, b]) => {
    return a.get() + b.get();
})

// If c is changed, for whatever reason, log it
watchReaction(c, (newC) => {
    console.log("Reaction completed: " + a.get() + " + " + b.get() + " = " + c.get());
});

// Test it by resetting a and b randomly

setInterval(() =>
{
    var newValue = Math.random();
    a.set(newValue); },
1000);

setInterval(() =>
{
    var newValue = Math.random();
    b.set(newValue); },
1300);

About

Reaktio.js is a small library which allows you to create a value that can be observed asynchronously.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published