refactor: StateProperty optimizations
This commit is contained in:
parent
9d618d1998
commit
e16e969170
|
@ -89,16 +89,27 @@ export class Trait extends Synchronized {
|
|||
}
|
||||
|
||||
export function StateProperty(key, meta = {}) {
|
||||
let transformedProperty;
|
||||
if (meta.transformProperty) {
|
||||
transformedProperty = meta.transformProperty(key);
|
||||
}
|
||||
else {
|
||||
transformedProperty = `$$avocado_state_property_${key}`;
|
||||
}
|
||||
return (Superclass) => {
|
||||
meta.emit = meta.emit || function(...args) {
|
||||
this.entity.emit(...args);
|
||||
};
|
||||
meta.get = meta.get || function(value) {
|
||||
return this.state.get(key);
|
||||
};
|
||||
meta.set = meta.set || function(value) {
|
||||
this.state = this.state.set(key, value);
|
||||
};
|
||||
meta.initialize = meta.initialize || function() {
|
||||
this[transformedProperty] = this.state.get(key);
|
||||
}
|
||||
meta.get = meta.get || new Function(`
|
||||
return this.${transformedProperty};
|
||||
`);
|
||||
meta.set = meta.set || new Function('value', `
|
||||
this.${transformedProperty} = value;
|
||||
this.state = this.state.set('${key}', value);
|
||||
`);
|
||||
return Property(key, meta)(Superclass);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user