refactor: simpleState now uses Property
This commit is contained in:
parent
c1e7db9ebf
commit
77ec2a3c04
|
@ -1,6 +1,7 @@
|
|||
import * as I from 'immutable';
|
||||
|
||||
import {Resource} from '@avocado/resource';
|
||||
import {Property} from '@avocado/mixins';
|
||||
|
||||
export class Trait {
|
||||
|
||||
|
@ -81,20 +82,17 @@ export class Trait {
|
|||
|
||||
}
|
||||
|
||||
export function simpleState(name) {
|
||||
export function simpleState(key, meta = {}) {
|
||||
return (Superclass) => {
|
||||
class SimpleState extends Superclass {}
|
||||
// Add simple state handler.
|
||||
Object.defineProperty(SimpleState.prototype, name, {
|
||||
get() {
|
||||
return this.state.get(name);
|
||||
},
|
||||
set(value) {
|
||||
this.state = this.state.set(name, value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
return SimpleState;
|
||||
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);
|
||||
};
|
||||
return Property(key, meta)(Superclass);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user