From 04eab70e2761925bf4772b2ea72106210f465ab4 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Sat, 24 Dec 2016 14:42:25 +0100 Subject: [PATCH] Add missing revision store --- src/libs/revisions.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/libs/revisions.js diff --git a/src/libs/revisions.js b/src/libs/revisions.js new file mode 100644 index 0000000..51abcf0 --- /dev/null +++ b/src/libs/revisions.js @@ -0,0 +1,35 @@ +export class RevisionStore { + constructor(initialRevisions=[]) { + this.revisions = initialRevisions + this.currentIdx = initialRevisions.length - 1 + } + + get latest() { + return this.revisions[this.revisions.length - 1] + } + + get current() { + return this.revisions[this.currentIdx] + } + + 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++ + } + + undo() { + if(this.currentIdx > 0) { + this.currentIdx-- + } + return this.current + } + + redo() { + if(this.currentIdx < this.revisions.length - 1) { + this.currentIdx++ + } + return this.current + } +}