avocado-old/packages/behavior/item/registry.js
2019-11-20 01:01:26 -06:00

27 lines
628 B
JavaScript

import {invokeHookFlat} from '@avocado/core';
let _behaviorItems;
export function fromJSON({type, ...json}) {
const items = behaviorItems();
const Class = items[type];
if (!Class) {
throw new TypeError(`There is no class for the behavior item "${type}"`);
}
return (new Class()).fromJSON(json);
}
function behaviorItems() {
if (!_behaviorItems) {
_behaviorItems = {};
const itemsLists = invokeHookFlat('avocadoBehaviorItems');
for (let i = 0; i < itemsLists.length; i++) {
_behaviorItems = {
..._behaviorItems,
...itemsLists[i],
};
}
}
return _behaviorItems;
}