https://github.com/michiel/state-recorder-js
A key, value state object that can emit or consume changes in JSON-PATCH format
https://github.com/michiel/state-recorder-js
json-diff json-patch
Last synced: about 1 year ago
JSON representation
A key, value state object that can emit or consume changes in JSON-PATCH format
- Host: GitHub
- URL: https://github.com/michiel/state-recorder-js
- Owner: michiel
- License: mit
- Created: 2016-01-25T18:23:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-02T12:50:13.000Z (over 10 years ago)
- Last Synced: 2025-02-10T14:33:49.290Z (over 1 year ago)
- Topics: json-diff, json-patch
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# state-recorder
A State object that can emit or consume changes in JSON-PATCH format
[](https://travis-ci.org/michiel/state-recorder-js)
[](https://codeclimate.com/github/michiel/state-recorder-js)
[](https://codeclimate.com/github/michiel/state-recorder-js)
[](https://david-dm.org/michiel/state-recorder-js)
[](https://david-dm.org/michiel/state-recorder-js#info=devDependencies)
## Example
$ npm run build
$ node
> SR = require('./dist/state-recorder').default
[Function: StateRecorder]
> var state = new SR()
undefined
> state.set('keyA', 'a')
undefined
> state.set('keyA', 'A')
undefined
> var patches = state.getReversePatches()
undefined
> patches
[ { op: 'remove', path: 'keyA' },
{ op: 'replace', path: 'keyA', value: 'a' } ]
> state.get('keyA')
'A'
> state.applyPatch(patches[1])
undefined
> state.get('keyA')
'a'
> state.applyPatch(patches[0])
undefined
> state.has('keyA')
false
> state.getPatches()
[ [ { op: 'remove', path: 'keyA' },
{ op: 'add', path: 'keyA', value: 'a' } ],
[ { op: 'replace', path: 'keyA', value: 'a' },
{ op: 'replace', path: 'keyA', value: 'A' } ],
[ { op: 'replace', path: 'keyA', value: 'A' },
{ op: 'replace', path: 'keyA', value: 'a' } ],
[ { op: 'add', path: 'keyA', value: 'a' },
{ op: 'remove', path: 'keyA' } ] ]