json-history
- A plugin can
redo
,undo
deep nested JSON. - Vue or React friendly.
- Support
Date
as value butregex
andfunction
- min+gzipped 12.2kB
- uses google-diff-match-patch for long text diffs (diff at character level)
- Import jsondiffpatch but without the formatter.
The source code still messy but works fine. I will refactor once have time.
Installing
yarn add json-history
const history = tree: object | array
Options
tree = {} steps = 50 // how many steps can redo backUpDeltas = // can backup the previous deltas callback = {} {} {} {} {} {} { Vue } { Vue }
Record / Redo / Undo
Update any value of object or array by multi records. Can redo
or undo
after record
.
Accept array or an object.
const history = tree: 1: 1 3 a: {} 1: 3 b: c: 5 d: e: 6 history history history historyhistoryhistoryhistoryhistory
Delete
Delete object key.
Same as record
with undefined
value.
const history = tree: 1: 1 3 a: {} 1: 3 b: c: 5 d: e: 6 history
Snapshot
Replace the whole tree and record a step.
const history = tree: 1 2 3 history history
Merge records
Can merge multi actions, such as delete
or record
.
const history = tree: 1: 1 3 a: {} 1: 3 b: c: 5 d: e: 6 history
Clean records
Can pass a function to check the delta should delete or not.
const shouldDeleteFunction = { const key = Object0 return key === 'this one should delete'}
const history = tree: 1: 1 3 a: {} 1: 3 b: c: 5 d: e: 6 history history history history history historyhistory
More cases
https://github.com/lustan3216/json-history/tree/master/tests