feat: hook type hints

This commit is contained in:
cha0s 2020-06-22 04:25:58 -05:00
parent de5957fd05
commit 3db24756d3

View File

@ -1,4 +1,4 @@
import {compose} from '@avocado/core';
import {compose, flatten} from '@avocado/core';
import {StateProperty, Trait} from '@avocado/entity';
import {Context} from '../context';
@ -24,7 +24,6 @@ export default class Behaved extends decorate(Trait) {
static defaultParams() {
return {
contextTypeHints: {},
routines: {},
};
}
@ -38,10 +37,6 @@ export default class Behaved extends decorate(Trait) {
static describeParams() {
return {
contextTypeHints: {
type: 'object',
label: 'Context type hints',
},
routines: {
type: 'routines',
label: 'Routines',
@ -71,8 +66,6 @@ export default class Behaved extends decorate(Trait) {
this._context = new Context({
entity: [this.entity, 'entity'],
});
Object.entries(this.params.contextTypeHints)
.forEach(([key, type]) => this._context.add(key, undefined, type));
this._currentRoutine = undefined;
this._routines = (new Routines()).fromJSON(this.params.routines);
this.updateCurrentRoutine(this.state.currentRoutine);
@ -103,6 +96,12 @@ export default class Behaved extends decorate(Trait) {
this.entity.isBehaving = !isDying;
},
traitAdded: (type) => {
console.log(flatten(this.entity.invokeHookFlat('contextTypeHints')))
flatten(this.entity.invokeHookFlat('contextTypeHints'))
.forEach(([key, type]) => this._context.add(key, undefined, type));
},
};
}