Add map node and refactor defaults

This commit is contained in:
Misode
2020-05-25 23:51:00 +02:00
parent 3620074c86
commit 387218193e
10 changed files with 135 additions and 65 deletions

View File

@@ -24,18 +24,14 @@ export class DataModel {
this.listeners.forEach(listener => listener.invalidated(this))
}
get(path: Path) {
set(path: Path, value: any) {
let node = this.data;
for (let index of path) {
if (node === undefined) node = {}
for (let index of path.pop()) {
if (node[index] === undefined) {
node[index] = {}
}
node = node[index]
}
return node
}
set(path: Path, value: any) {
let node = this.get(path.pop())
if (node === undefined) node = {}
console.log('Set', path.toString(), JSON.stringify(value))