From 8a1a5ac42baaca86be4394adc4a9788a6f0cab20 Mon Sep 17 00:00:00 2001 From: Craig Kochis Date: Fri, 31 Mar 2023 19:38:08 -0400 Subject: [PATCH] only store changes as revisions --- src/libs/revisions.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libs/revisions.js b/src/libs/revisions.js index 51abcf00..e80c3dce 100644 --- a/src/libs/revisions.js +++ b/src/libs/revisions.js @@ -1,3 +1,5 @@ +import {diff} from '@mapbox/mapbox-gl-style-spec' + export class RevisionStore { constructor(initialRevisions=[]) { this.revisions = initialRevisions @@ -13,10 +15,17 @@ export class RevisionStore { } addRevision(revision) { - //TODO: compare new revision style id with old ones - //and ensure that it is always the same id - this.revisions.push(revision) - this.currentIdx++ + // only store revision if has changes + const changes = diff(revision, this.current); + if (changes.length > 0) { + + // 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() {