1 |
|
2 |
|
3 |
|
4 |
|
5 | const broadcast = require('broadcast');
|
6 |
|
7 | module.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 | };
|