refactor: restructure traits, no autoregister
This commit is contained in:
parent
a02353f95a
commit
3b0efe4e9b
|
@ -138,6 +138,6 @@ export {
|
||||||
hasTrait,
|
hasTrait,
|
||||||
lookupTrait,
|
lookupTrait,
|
||||||
registerTrait,
|
registerTrait,
|
||||||
} from './traits/registry';
|
} from './trait-registry';
|
||||||
|
|
||||||
export {simpleState, Trait} from './trait';
|
export {simpleState, Trait} from './trait';
|
||||||
|
|
13
packages/entity/trait-registry.js
Normal file
13
packages/entity/trait-registry.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const traitRegistry = new Map();
|
||||||
|
|
||||||
|
export function registerTrait(Trait) {
|
||||||
|
traitRegistry.set(Trait.type(), Trait);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasTrait(type) {
|
||||||
|
return traitRegistry.has(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function lookupTrait(type) {
|
||||||
|
return traitRegistry.get(type);
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import * as I from 'immutable';
|
||||||
|
|
||||||
import {Resource} from '@avocado/resource';
|
import {Resource} from '@avocado/resource';
|
||||||
|
|
||||||
import {hasTrait, lookupTrait, registerTrait} from './registry';
|
import {hasTrait, lookupTrait, registerTrait} from './trait-registry';
|
||||||
|
|
||||||
function enumerateProperties(prototype) {
|
function enumerateProperties(prototype) {
|
||||||
const result = {};
|
const result = {};
|
|
@ -1,35 +0,0 @@
|
||||||
// import {registerType} from '@avocado/behavior';
|
|
||||||
|
|
||||||
const traitRegistry = new Map();
|
|
||||||
|
|
||||||
export function registerTrait(Trait) {
|
|
||||||
traitRegistry.set(Trait.type(), Trait);
|
|
||||||
// registerType(`entity:trait:${Trait.type()}`, Trait.contextType());
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hasTrait(type) {
|
|
||||||
return traitRegistry.has(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function lookupTrait(type) {
|
|
||||||
return traitRegistry.get(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register core traits.
|
|
||||||
import {Animated} from './animated';
|
|
||||||
registerTrait(Animated);
|
|
||||||
|
|
||||||
import {Directional} from './directional';
|
|
||||||
registerTrait(Directional);
|
|
||||||
|
|
||||||
import {Existent} from './existent';
|
|
||||||
registerTrait(Existent);
|
|
||||||
|
|
||||||
import {Graphical} from './graphical';
|
|
||||||
registerTrait(Graphical);
|
|
||||||
|
|
||||||
import {Mobile} from './mobile';
|
|
||||||
registerTrait(Mobile);
|
|
||||||
|
|
||||||
import {Positioned} from './positioned';
|
|
||||||
registerTrait(Positioned);
|
|
Loading…
Reference in New Issue
Block a user