UNPKG

active-data

Version:

Reactive data manager, inspired by MobX. Automatically detects associated data and perform updates to your views or everything dependent on that data when it changes. Implemented with js Proxy objects

27 lines (20 loc) 703 B
const ad = require("active-data"); ad.setOptions({ immediateReaction: true, // make recalculations for each change }); const data = ad.makeObservable({ welcomeMessage: "Hello,", firstName: "Luke", lastName: "Skywalker", }); ad.makeComputed(data, "fullName", self => `${self.firstName} ${self.lastName}`); ad.makeReaction(() => { console.log(data.welcomeMessage + " " + data.fullName); }); // "Hello, Luke Skywalker" will be printed immediately (can be configured) data.firstName = "Leia"; // will print "Hello, Leia Skywalker" ad.run(() => { // group changes together and run reaction functions only at the end data.firstName = "Anakin"; data.welcomeMessage = "Welcome to dark side,"; });