addon-sdk/source/lib/diffpatcher/patch.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/lib/diffpatcher/patch.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,21 @@
     1.4 +"use strict";
     1.5 +
     1.6 +var method = require("../method/core")
     1.7 +var rebase = require("./rebase")
     1.8 +
     1.9 +// Method is designed to work with data structures representing application
    1.10 +// state. Calling it with a state and delta should return object representing
    1.11 +// new state, with changes in `delta` being applied to previous.
    1.12 +//
    1.13 +// ## Example
    1.14 +//
    1.15 +// patch(state, {
    1.16 +//   "item-id-1": { completed: false }, // update
    1.17 +//   "item-id-2": null                  // delete
    1.18 +// })
    1.19 +var patch = method("patch@diffpatcher")
    1.20 +patch.define(Object, function patch(hash, delta) {
    1.21 +  return rebase({}, hash, delta)
    1.22 +})
    1.23 +
    1.24 +module.exports = patch

mercurial