const behaviorItemRegistry = new Map(); export function fromJSON({type, ...json}) { const Class = behaviorItemRegistry.get(type); if (!Class) { throw new TypeError(`There is no class for the behavior item "${type}"`); } return (new Class()).fromJSON(json); } export function deregister(BehaviorItem) { behaviorItemRegistry.delete(BehaviorItem.type()); } export function register(BehaviorItem) { if (!BehaviorItem.type) { BehaviorItem.type = function() { return BehaviorItem.name.toLowerCase(); } } behaviorItemRegistry.set(BehaviorItem.type(), BehaviorItem); }