UNPKG

639 BJavaScriptView Raw
1// CAVEAT: Custom Elements MUST be defined upfront
2// There is no instance upgrade since it's
3// not possible to reproduce it procedurally.
4
5const broadcast = require('broadcast');
6
7module.exports = class CustomElementRegistry {
8
9 constructor() {
10 this._registry = Object.create(null);
11 }
12
13 define(name, constructor, options) {
14 if (name in this._registry)
15 throw new Error(name + ' already defined');
16 this._registry[name] = constructor;
17 broadcast.that(name, constructor);
18 }
19
20 get(name) {
21 return this._registry[name] || null;
22 }
23
24 whenDefined(name) {
25 return broadcast.when(name);
26 }
27
28};