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:
Harel M
2023-12-21 00:07:53 +02:00
committed by GitHub
parent e8d07fa694
commit 3bf0e510e6
15 changed files with 149 additions and 96 deletions
+41
View File
@@ -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;
}
}