Skip to content

A key, value state object that can emit or consume changes in JSON-PATCH format

License

Notifications You must be signed in to change notification settings

michiel/state-recorder-js

Repository files navigation

state-recorder

A State object that can emit or consume changes in JSON-PATCH format

Travis build status Code Climate Test Coverage Dependency Status devDependency Status

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' } ] ]

About

A key, value state object that can emit or consume changes in JSON-PATCH format

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published