avocado-old/packages/behavior/item/registry.js

27 lines
628 B
JavaScript
Raw Normal View History

2019-11-20 01:01:26 -06:00
import {invokeHookFlat} from '@avocado/core';
let _behaviorItems;
2019-03-17 23:45:48 -05:00
export function fromJSON({type, ...json}) {
2019-11-20 01:01:26 -06:00
const items = behaviorItems();
const Class = items[type];
2019-03-17 23:45:48 -05:00
if (!Class) {
throw new TypeError(`There is no class for the behavior item "${type}"`);
}
return (new Class()).fromJSON(json);
}
2019-11-20 01:01:26 -06:00
function behaviorItems() {
if (!_behaviorItems) {
_behaviorItems = {};
const itemsLists = invokeHookFlat('avocadoBehaviorItems');
for (let i = 0; i < itemsLists.length; i++) {
_behaviorItems = {
..._behaviorItems,
...itemsLists[i],
};
}
}
return _behaviorItems;
2019-03-17 23:45:48 -05:00
}