New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

observejs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

observejs

Watch a Javascript object for changes and stream changes to another object

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

observejs

Watch a Javascript object for changes and stream changes to another object using node.js Streams.

Installation

Install with npm:

$ npm install observejs

Example

var observejs = require('observejs');

// the source object
var o = {
  name: 'Eugene',
  number: 42,
  tags: ['tag1', 'tag2', 'tag3'],
  cars: [
    {
      make: 'Toyota',
      model: 'Camry'
    },
    {
      make: 'Toyota',
      model: 'Corolla'
    }
  ]
};

// deep clone of o
var o2 = JSON.parse(JSON.stringify(o));

// Replicate any changes to o2
observejs.observe(o)
  .pipe(observejs.changes(o2));

// Make some changes to the source object
o.name = 'Susan';
o.number = 43;
o.number = undefined;
o.cars[0].make = 'Holden';
o.cars.push({
  make: 'BMW',
  model: 'M3'
});

// o and o2 should be equal
expect(o2).to.deep.equals(o);

methods

var observejs = require('observerjs');

observejs.observe(src)

Watch the object src for any changes. Returns a stream which can be used with observerjs.changes(dest) to keep another object in sync.

observejs.unobserve(src)

Stop watching the object src.

observejs.changes(dest)

Stream which takes the data from an observerjs.observer(src) and keeps the target object dest in sync with the source.

Keywords

Object.observe

FAQs

Package last updated on 17 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts