1.0.9 • Published 10 years ago

ampersand-json-patch v1.0.9

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

ampersand-json-patch

Adds JSON Patch (RFC 6902) support to Ampersand models.

###Don't patch like an idiot.

Usage

npm install --save ampersand-json-patch

ampersand-json-patch is used as a mixin.

var AmpersandModel = require('ampersand-model');
var PatchMixin = require('ampersand-patch-json');

var CarModel = AmpersandModel.extend(PatchMixin, {
	urlRoot: '/api/cars',
	props: {
		id: 'number',
		make: 'string',
		model: 'string',
		year: 'number'
	},
	initialize: function() {
		this.initPatcher();
	}
});

Models now have a patch() method.

var myCar = new CarModel({id: 1, make: 'Honda', model: 'CR-V', year: 1999});

myCar.set({model: 'Civic'});

myCar.patch();

Generates the following HTTP PATCH request to /api/cars/1:

[ { op: 'replace', path: '/model', value: 'Civic' } ]

The patch method also accepts success and error callbacks in the options hash, just like Ampersand's save.

Initializing the patcher with initPatcher({listeners: true}) will fire a patch to the server automatically on every change event to your model.

See JSON-Patch for all supported operations.

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago