refactor: simpleState now uses Property

This commit is contained in:
cha0s 2019-03-18 20:04:12 -05:00
parent c1e7db9ebf
commit 77ec2a3c04

View File

@ -1,6 +1,7 @@
import * as I from 'immutable'; import * as I from 'immutable';
import {Resource} from '@avocado/resource'; import {Resource} from '@avocado/resource';
import {Property} from '@avocado/mixins';
export class Trait { export class Trait {
@ -81,20 +82,17 @@ export class Trait {
} }
export function simpleState(name) { export function simpleState(key, meta = {}) {
return (Superclass) => { return (Superclass) => {
class SimpleState extends Superclass {} meta.emit = meta.emit || function(...args) {
// Add simple state handler. this.entity.emit(...args);
Object.defineProperty(SimpleState.prototype, name, { };
get() { meta.get = meta.get || function(value) {
return this.state.get(name); return this.state.get(key);
}, };
set(value) { meta.set = meta.set || function(value) {
this.state = this.state.set(name, value); this.state = this.state.set(key, value);
}, };
enumerable: true, return Property(key, meta)(Superclass);
configurable: true,
});
return SimpleState;
} }
} }