An object with observable key value pairs
JavaScript OCaml
Latest commit 1e045d3 May 6, 2015 @Raynos Merge pull request #10 from wenbing/master
upgrade xtend@4
Failed to load latest commit information.
test blacklist length too Oct 8, 2014
.gitignore initial version Feb 21, 2014
.jshintrc initial version Feb 21, 2014
.travis.yml initial version Feb 21, 2014
LICENCE initial version Feb 21, 2014 Fix example Sep 20, 2014
docs.mli rename to observ-struct Jun 2, 2014
index.js blacklist length too Oct 8, 2014
package.json upgrade xtend@4 May 2, 2015


An object with observable key value pairs


An observable will emit a new immutable value whenever one of its keys changes.

Nested keys will still be the same value if they were not changed in that particular .set() call.

var ObservStruct = require("observ-struct")
var Observ = require("observ")
var assert = require("assert")

var state = ObservStruct({
    fruits: ObservStruct({
        apples: Observ(3),
        oranges: Observ(5)
    customers: Observ(5)

state(function (current) {
  console.log("apples", current.fruits.apples)
  console.log("customers", current.customers)

state.fruits(function (current) {
  console.log("apples", current.apples)

var initialState = state()
assert.equal(initialState.fruits.oranges, 5)
assert.equal(initialState.customers, 5)



var obj = ObservStruct(opts)

ObservStruct() takes an object literal of string keys to either normal values or observable values.

It returns an Observ instance obj. The value of obj is a plain javascript object where the value for each key is either the normal value passed in or the value of the observable for that key.

Whenever one of the observables on a key changes the obj will emit a new object that's a shallow copy with that key set to the value of the appropiate observable on that key.


npm install observ-struct


  • Raynos

MIT Licenced