observ
A observable value representation
Last updated 12 years ago by raynos .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install observ 
SYNC missed versions from official npm registry.

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")
v(function onchange(newValue) {
  assert.equal(newValue, "new value")
})
v.set("new value")

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

What about dominictarr/observable ?

Both observ & observable have the same interface of

  • thing() gets the value
  • thing.set(...) sets the value
  • thing(function (value) { ... }) listens to the value.

The way observ and observable differ is in listening.

  • observ will ONLY call the listener if .set() is invoked.
  • observable calls the listener IMMEDIATELY and calls it whenever .set() is invoked

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.

  • require("observable").compute
  • require("observ/computed")

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>

Installation

npm install observ

Contributors

  • Raynos

MIT Licenced

Current Tags

  • 0.2.0                                ...           latest (12 years ago)

8 Versions

  • 0.2.0                                ...           12 years ago
  • 0.1.6                                ...           12 years ago
  • 0.1.5                                ...           13 years ago
  • 0.1.4                                ...           13 years ago
  • 0.1.3                                ...           13 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 8
Last Day 0
Last Week 8
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |