mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 08:35:25 +01:00
Add missing revision store
This commit is contained in:
parent
cfbcdc7fa1
commit
04eab70e27
1 changed files with 35 additions and 0 deletions
35
src/libs/revisions.js
Normal file
35
src/libs/revisions.js
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue