patch.js 602 B

123456789101112131415161718192021
  1. "use strict";
  2. var method = require("../method/core")
  3. var rebase = require("./rebase")
  4. // Method is designed to work with data structures representing application
  5. // state. Calling it with a state and delta should return object representing
  6. // new state, with changes in `delta` being applied to previous.
  7. //
  8. // ## Example
  9. //
  10. // patch(state, {
  11. // "item-id-1": { completed: false }, // update
  12. // "item-id-2": null // delete
  13. // })
  14. var patch = method("patch@diffpatcher")
  15. patch.define(Object, function patch(hash, delta) {
  16. return rebase({}, hash, delta)
  17. })
  18. module.exports = patch