A Standalone version of ReactiveVar package from Meteor. Lets you write reactive code with ease outside of Meteor
npm install --save reactive-var-std
<script src="//cdn.jsdelivr.net/reactive-var-std/1.1.4/reactive-var-std.min.js"></script>
<!-- OR -->
<script src="//cdn.jsdelivr.net/reactive-var-std/latest/reactive-var-std.min.js"></script>
import StdReactiveVar, { Tracker } from 'reactive-var-std';
// or if you do not use ES6
// var StdReactiveVar = require('reactive-var-std');
// var Tracker = StdReactiveVar.Tracker;
// var StdReactiveVar = StdReactiveVar.default;
// create a creative var instance
const reactive = new StdReactiveVar(0);
// wrap the reactive instance inside a computation block created by Tracker.autorun
Tracker.autorun(() => {
// log the value whenever it changes
console.log(reactive.get());
});
// change the value 1st time
reactive.set(1);
// ---> the console will show: 1
// change the value 1st time
reactive.set(10);
// ---> the console will show: 10
var StdReactiveVar = require('reactive-var-std');
var Tracker = StdReactiveVar.Tracker;
var StdReactiveVar = StdReactiveVar.default;
// create a creative var instance
var reactive = new StdReactiveVar(0);
// wrap the reactive instance inside a computation block created by Tracker.autorun
Tracker.autorun(function() {
// log the value whenever it changes
console.log(reactive.get());
});
// change the value 1st time
reactive.set(1);
// ---> the console will show: 1
// change the value 1st time
reactive.set(10);
// ---> the console will show: 10