1.0.0 • Published 4 years ago

jsonpatch-observe v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Build Status

Observe an object tree for changes and generate JSON Patches (RFC 6902). Uses Harmony Proxy, available in NodeJS version 6.4 and above.

Usage

const {observe} = require("jsonpatch-observe");

let observable = observe({});
observable.$subscribe(patch => console.log(patch));
observable.a = {b:1};		//prints {op:"add", path:"a", value:{b:1}}
observable.a.b = 2;		//prints {op:"add", path:"a/b", value:2}
delete observable.a;		//prints {op:"remove", path:"a"}

Note that the properties of an Observable are also Observables. This is how it's able to detect when you do observable.a.b = 2.

Unobserved Properties

You can exclude certain properties from observe as follows:

require("jsonpatch-observe").config.excludeProperty = function(obj, prop) {
	//return true to exclude the property
}

Splice Patch

The JSONPatch standard does not specify a "splice" operation. Without splice, Array changes are represented as a series of individual "add", "replace", and "remove" operations, which can be quite inefficient to apply.

This module supports generating the splice patch. Enable it as follows:

require("jsonpatch-observe").config.enableSplice = true;

The splice patch has the following format:

{
	op: "splice",
	path: "/myarr/3",		//path to array index
	remove: 2,			//number of elements removed
	add: ['a','b','c']		//elements added
}

I created a fork of Starcounter-Jack JSONPatch library capable of consuming this non-standard splice patch.

1.0.0

4 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago