mirror of
https://github.com/maputnik/editor.git
synced 2026-08-26 06:57:26 +00:00
only store changes as revisions
This commit is contained in:
+13
-4
@@ -1,3 +1,5 @@
|
|||||||
|
import {diff} from '@mapbox/mapbox-gl-style-spec'
|
||||||
|
|
||||||
export class RevisionStore {
|
export class RevisionStore {
|
||||||
constructor(initialRevisions=[]) {
|
constructor(initialRevisions=[]) {
|
||||||
this.revisions = initialRevisions
|
this.revisions = initialRevisions
|
||||||
@@ -13,10 +15,17 @@ export class RevisionStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addRevision(revision) {
|
addRevision(revision) {
|
||||||
//TODO: compare new revision style id with old ones
|
// only store revision if has changes
|
||||||
//and ensure that it is always the same id
|
const changes = diff(revision, this.current);
|
||||||
this.revisions.push(revision)
|
if (changes.length > 0) {
|
||||||
this.currentIdx++
|
|
||||||
|
// clear any "redo" revisions once a change is made
|
||||||
|
// and ensure current index is at end of list
|
||||||
|
this.revisions = this.revisions.slice(0, this.currentIdx + 1);
|
||||||
|
|
||||||
|
this.revisions.push(revision)
|
||||||
|
this.currentIdx++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
undo() {
|
undo() {
|
||||||
|
|||||||
Reference in New Issue
Block a user