1.1.1 • Published 9 years ago

observify-varhash v1.1.1

Weekly downloads
3
License
BSD
Repository
github
Last release
9 years ago

observify-varhash

This is just a fork of observify, but uses observ-varhash for objects instead of observ-struct so that keys can be added and removed.

Converts JS objects into their observable equivalents using observ, observ-array and observ-varhash. Designed for use with mercury

NPM

installation

npm install observify-varhash

usage

var observify = require('observify-varhash')
var data = observify({
  "foo": "bar",
  "cats": ["taco", "burrito"],
  "age": 82
})

is equivalent to doing:

var array = require('observ-array')
var varhash = require('observ-varhash')
var value = require('observ')

var data = varhash({
  "foo": value("bar"),
  "cats": array([value("taco"), value("burrito")]),
  "age": value(82)
})

blacklisted properties

observ-varhash has a blacklist of property names that cannot be used as keys (as they clash with javascript reserved words).

You can pass an options object with a autoRename property to tell observify to rename these properties.

var observify = require('observify-varhash')
var data = observify({
  "name":"I'm bad, I'm bad, you know it",
  "comment":"I am OK"
}, {
  autoRename:'$'
})

console.log(data())

This would print:

{
  $name:"I'm bad, I'm bad, you know it",
  comment:"I am OK"
}

If autoRename is true it will default to $.