automatic syncing of members on change. Closes #2
parent
f604948d71
commit
7a12c1adb8
|
|
@ -1,2 +1,3 @@
|
||||||
node_modules
|
node_modules
|
||||||
out
|
out
|
||||||
|
.system
|
||||||
|
|
@ -2,4 +2,5 @@ node_modules
|
||||||
src
|
src
|
||||||
test
|
test
|
||||||
.editorconfig
|
.editorconfig
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
|
.system
|
||||||
|
|
@ -52,8 +52,11 @@ export default class Instance {
|
||||||
initialContext[link.name] = [];
|
initialContext[link.name] = [];
|
||||||
for(const link of this.module.links.filter((v: Link) => !v.array && !v.required))
|
for(const link of this.module.links.filter((v: Link) => !v.array && !v.required))
|
||||||
initialContext[link.name] = null;
|
initialContext[link.name] = null;
|
||||||
for(const variable of this.module.variables)
|
for(const variable of this.module.variables) {
|
||||||
initialContext[variable.name] = null;
|
attachHookedProperty(initialContext, variable.name, null, () => {
|
||||||
|
this.system.saveInstance(this);
|
||||||
|
})
|
||||||
|
}
|
||||||
for(const name in this.module.imports)
|
for(const name in this.module.imports)
|
||||||
initialContext[name] = this.module.imports[name];
|
initialContext[name] = this.module.imports[name];
|
||||||
|
|
||||||
|
|
@ -133,4 +136,19 @@ ${name} = ${name}.bind(this);
|
||||||
toString() {
|
toString() {
|
||||||
return this.module.name.full + '(' + this._id + ')';
|
return this.module.name.full + '(' + this._id + ')';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachHookedProperty(target: any, name: string, initialValue: any, changedHook: () => void) {
|
||||||
|
const propId = uuid.v4();
|
||||||
|
target[propId] = initialValue;
|
||||||
|
// TODO if its an object, replace it with a dead simple proxy? for detecting internal changes...
|
||||||
|
Object.defineProperty(target, name, {
|
||||||
|
get() {
|
||||||
|
return target[propId];
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
target[propId] = value;
|
||||||
|
changedHook();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,6 @@ member count;
|
||||||
|
|
||||||
increment() {
|
increment() {
|
||||||
count ++;
|
count ++;
|
||||||
sync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCount() {
|
getCount() {
|
||||||
|
|
|
||||||
Reference in New Issue