reactive-var-std

1.1.6 • Public • Published

Standalone Reactive Var

CircleCI Coverage Status npm version dependencies Known Vulnerabilities

A Standalone version of ReactiveVar package from Meteor. Lets you write reactive code with ease outside of Meteor

Check out the demo here

Install

NPM
npm install --save reactive-var-std
CDN
<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>

Usage

ES6
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
ES5
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

API

StdReactiveVar(v:Any)

.get()

.set(v:Any)

.getOld()

.getNonReactive()

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i reactive-var-std

Weekly Downloads

0

Version

1.1.6

License

MIT

Last publish

Collaborators

  • khangnlh