|
@@ -26,7 +26,7 @@ export class Store {
|
|
|
|
|
|
constructor(name) {
|
|
|
this.name = name;
|
|
|
- this.store = {};
|
|
|
+ this.store = new Map();
|
|
|
this.nextStore = null;
|
|
|
this.mode = Modes.RUN;
|
|
|
}
|
|
@@ -36,22 +36,22 @@ export class Store {
|
|
|
}
|
|
|
|
|
|
applyStore (id) {
|
|
|
- if(!this.store[id]) {
|
|
|
+ if(!this.store.has(id)) {
|
|
|
if (this.nextStore !== null) {
|
|
|
return this.nextStore.applyStore(id);
|
|
|
} else {
|
|
|
throw new Error(`Variable ${id} not found.`);
|
|
|
}
|
|
|
}
|
|
|
- const val = this.store[id];
|
|
|
+ const val = this.store.get(id);
|
|
|
if (val.isRef) {
|
|
|
return val.getRefObj();
|
|
|
}
|
|
|
- return this.store[id];
|
|
|
+ return val;
|
|
|
}
|
|
|
|
|
|
updateStore (id, stoObj) {
|
|
|
- if(!this.store[id]) {
|
|
|
+ if(!this.store.has(id)) {
|
|
|
if(this.nextStore !== null) {
|
|
|
this.nextStore.updateStore(id, stoObj);
|
|
|
return this;
|
|
@@ -60,7 +60,7 @@ export class Store {
|
|
|
throw new Error(`Variable ${id} not found.`);
|
|
|
}
|
|
|
} else {
|
|
|
- const oldObj = this.store[id];
|
|
|
+ const oldObj = this.store.get(id);
|
|
|
if(oldObj.readOnly) {
|
|
|
// TODO: better error message
|
|
|
throw new Error("Cannot change value of a read only variable: " + id);
|
|
@@ -72,8 +72,8 @@ export class Store {
|
|
|
const newObj = stoObj.copy();
|
|
|
stoObj.destroy();
|
|
|
newObj.setID(id);
|
|
|
- this.store[id].destroy();
|
|
|
- this.store[id] = newObj;
|
|
|
+ this.store.get(id).destroy();
|
|
|
+ this.store.set(id, newObj);
|
|
|
return this;
|
|
|
} else {
|
|
|
const oldType = oldObj.type;
|
|
@@ -89,12 +89,12 @@ export class Store {
|
|
|
// updateStoreRef(id, stoObjAddress) {...}
|
|
|
|
|
|
insertStore (id, stoObj) {
|
|
|
- if (this.store[id]) {
|
|
|
+ if (this.store.has(id)) {
|
|
|
// TODO: better error message
|
|
|
throw new Error(`${id} is already defined`);
|
|
|
}
|
|
|
stoObj.setID(id);
|
|
|
- this.store[id] = stoObj;
|
|
|
+ this.store.set(id, stoObj);
|
|
|
return this;
|
|
|
}
|
|
|
/**
|
|
@@ -102,13 +102,13 @@ export class Store {
|
|
|
* applyStore will return the refferenced object if the object in the store is a ref
|
|
|
*/
|
|
|
getStoreObject (id) {
|
|
|
- if(!this.store[id]) {
|
|
|
+ if(!this.store.has(id)) {
|
|
|
if (this.nextStore !== null) {
|
|
|
return this.nextStore.getStoreObject(id);
|
|
|
} else {
|
|
|
throw new Error(`Variable ${id} not found.`);
|
|
|
}
|
|
|
}
|
|
|
- return this.store[id];
|
|
|
+ return this.store.get(id);
|
|
|
}
|
|
|
}
|