npm.io
0.1.2 • Published 11 years ago

cruddy

Licence
Version
0.1.2
Deps
0
Vulns
0
Weekly
0

CruddyJS - Observable Objects for the laggards

Observe changes to native JavaScript objects with CruddyJS. Based on the EcmaScript Harmony proposal, CruddyJS will send change updates when object values change. Here's how it works.

var observer = cruddy({ foo: 'bar' }, function (changes) {
 console.log(changes);
})

observer.update(function (o) {
 o.set('foo', 'boo')
})

> {
 type: 'update',
 name: 'foo',
 object: { foo: 'boo' },
 oldValue: 'bar'
}

Does your browser already support Object.observe? No problem, CruddyJS simply uses the native functionality.

Installation

NodeJS

npm install cruddy

API

Depending on the type of class passed to CruddyJS, you will get one of two interfaces. For basic Object classes you will receive a Model. For Array classes you will receive a Collection.

Model
cruddy({ foo: 'bar' }, callback)
.update(function (model) {
  model.set('bar', 'foo')
  model.destroy('foo', 'bar')
})
Methods
  • get
  • set
  • destroy
Collection
cruddy([1, 3, 2], callback)
.update(function (collection) {
  collection.push(0, 4, 5)
  collection.shift()
  collection.sort()
})
Methods
  • concat
  • length
  • get
  • join
  • set
  • push
  • pop
  • reverse
  • shift
  • splice
  • unshift

EcmaScript 6+

  • forEach
  • indexOf
  • fill
  • lastIndexOf
  • map
  • reduce
  • reduceRight
  • some