18 lines
477 B
JavaScript
18 lines
477 B
JavaScript
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) {
|
|
behaviorItemRegistry.set(BehaviorItem.type(), BehaviorItem);
|
|
}
|