mirror of
https://github.com/maputnik/editor.git
synced 2026-08-25 14:37:27 +00:00
Migrate all the non react components code to typescript (#847)
This completes the migration to typescript of all the non react components code. The only changes introduced besides types are the type checks using `"something" in object` which narrows down types in typescript.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type {StyleSpecification} from "@maplibre/maplibre-gl-style-spec";
|
||||
|
||||
export class RevisionStore {
|
||||
revisions: StyleSpecification[];
|
||||
currentIdx: number;
|
||||
|
||||
|
||||
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: StyleSpecification) {
|
||||
//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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user