Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including reactive-var-std with all npm packages installed. Try it out:

var reactiveVarStd = require("reactive-var-std")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

reactive-var-std v1.1.6

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

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free