Skip to content
Atomic observable value interface
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.lint
.travis.yml
CHANGES
LICENSE
README.md
_and-or.js
_eq.js
_reduce.js
add.js
and.js
create-read-only.js
eq-sloppy.js
eq-some.js
eq.js
gt-or-eq.js
gt.js
if.js
index.js
is-observable-value.js
is-observable.js
lt-or-eq.js
lt.js
map.js
not.js
or.js
package.json
resolve.js
subtract.js
symbol-is-observable.js
valid-observable-value.js
valid-observable.js

README.md

observable-value

Object representation of mutable value

Usage

var ObservableValue = require('observable-value');

var observable = new ObservableValue('foo');

Current value is accessible at value property:

observable.value; // 'foo'

change events are emitted on any change

var emitted;
observable.on('change', function (event) { emitted = event; });
obj.value = 'bar';
console.log(emitted); // { newValue: 'bar', oldValue: 'foo' };

Installation

$ npm install observable-value

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Additional utilities

isObservableValue (observable-value/is-observable-value)

Whether object shares ObservableValue interface

var isObservableValue = require('observable-value/is-observable-value');

console.log(isObservableValue({})); // false
console.log(isObservableValue(new ObservableValue())); // true

eq

Create observable value out of two different values that may share ObservableValue but don't have to. If both values do not represent ObservableValue, plain boolean value is returned

var eq = require('observable-value/eq');

console.log(isObservableValue(eq('foo', 'bar'))); // false
console.log(eq('foo', 'bar')); // false
console.log(eq('foo', 'foo')); // true

var m1 = new ObservableValue();

var em = eq(m1, 'foo');
console.log(isObservableValue(em)); // true
console.log(em.value); // false
em.on('change', function (value) { emitted = value; });
m1.value = 'foo';
console.log(emitted); // true
console.log(em.value); // true
m1.value = 'bar';
console.log(emitted); // false
console.log(em.value); // false

emitted = null;
m1.value = 'other';
console.log(emitted); // null
console.log(em.value); // false

var m2 = new ObservableValue();
m2.value = 'other';
em = eq(m1, m2);
console.log(em.value); // true
m2.value = 'foo';
console.log(em.value); // false
m1.value = 'foo';
console.log(em.value); // true

Tests Build Status

$ npm test
Something went wrong with that request. Please try again.