* @static registerComponent - Register a Component to the components list. * All components should be registered before calling the init () method so * their Mounting cycle is done correctly. * * @param {Component} component - Component to register. Remember each * component must hav
(component: StaticComponent)
| 904 | * component must have an unique ID. |
| 905 | */ |
| 906 | static registerComponent (component: StaticComponent) { |
| 907 | const alreadyRegistered = this.components ().findIndex (c => c.tag === component.tag) > -1; |
| 908 | |
| 909 | if (typeof window.customElements.get (component.tag) !== 'undefined') { |
| 910 | FancyError.show ('engine:component:already_registered', { |
| 911 | tag: component.tag, |
| 912 | component: component, |
| 913 | unregisterCode: `<pre><code class='language-javascript'>monogatari.unregisterComponent ('${component.tag}')</code></pre>` |
| 914 | }); |
| 915 | } |
| 916 | |
| 917 | component.engine = this.asEngine(); |
| 918 | |
| 919 | if (alreadyRegistered && !this.global ('_didSetup')) { |
| 920 | // Remove the previous one |
| 921 | this.unregisterComponent (component.tag); |
| 922 | } else if (!alreadyRegistered && this.global ('_didSetup')) { |
| 923 | Registry.register(component.tag, component); |
| 924 | } |
| 925 | |
| 926 | this._components.push (component); |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * @static unregisterComponent - Removes a component from the components list. |
nothing calls this directly
no test coverage detected