From 77ec2a3c04413dd9f361c2d1c7668589cf6a9f1b Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 18 Mar 2019 20:04:12 -0500 Subject: [PATCH] refactor: simpleState now uses Property --- packages/entity/trait.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/entity/trait.js b/packages/entity/trait.js index 8ff9b7b..2258286 100644 --- a/packages/entity/trait.js +++ b/packages/entity/trait.js @@ -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); } }