Home

Awesome

observ

build status NPM version Davis Dependency status

browser support

NPM

A observable value representation

Example

var Observable = require("observ")

var v = Observable("initial value")
var stopListening = v(function onchange(newValue) {
  assert.equal(newValue, "new value")
})
v.set("new value")

var curr = v()
assert.equal(curr, "new value")
stopListening()

What about dominictarr/observable ?

Both observ & observable have the same interface of

The way observ and observable differ is in listening.

observ can be used in a similar fashion to observable by using var watch = require("observ/watch"). You can then just watch(thing, function (value) { ... }) and it will call the listener immediately

Both observ & observable have a computed method with the same interface.

Example computed

var Observable = require("observ")
var computed = require("observ/computed")

var one = Observable(1)
var two = Observable(2)

var together = computed([one, two], function (a, b) {
  return a + b
})

assert.equal(together(), 3)
two.set(5)
assert.equal(together(), 7)

Docs

type Observable<A> :
  (() => A) &
  ((Function<A>) => void) & {
    set: (A) => void
  }


observ : (A) => Observable<A>

observ/computed : (
  sources: Array<Observ<T>>,
  lambda: (...args: T) => S
) => Observ<S>

Installation

npm install observ

Contributors

MIT Licenced