Skip to content

Update an object tree by simply dump entire object in and observing changes of keypaths

Notifications You must be signed in to change notification settings

d6u/observe-object-path

Repository files navigation

Observe Object Path

npm version Circle CI

Usage

npm install -S observe-object-path
var ObserveObjectPath = require('observe-object-path').ObserveObjectPath;

var obj = {
  nested: {
    prop: 'propVal'
  }
};

var oop = new ObserveObjectPath(obj);

oop.on(['nested', 'prop'], (val) => console.log(val));

oop.update({
  nested: {
    prop: 'propNewVal'
  }
});

// Log 'propNewVal' after `update` is called

API

constructor(object: any)

on(path: string[], handler: (val: any) => void)

addEventListener(path: string[], handler: (val: any) => void)

off(path: string[], handler?: (val: any) => void)

removeEventListener(path: string[], handler?: (val: any) => void)

update(object: any)

About

Update an object tree by simply dump entire object in and observing changes of keypaths

Resources

Stars

Watchers

Forks

Packages

No packages published