MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / registerComponent

Method registerComponent

src/monogatari.ts:906–927  ·  view source on GitHub ↗

* @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)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 7

componentsMethod · 0.95
asEngineMethod · 0.95
globalMethod · 0.95
unregisterComponentMethod · 0.95
registerMethod · 0.80
getMethod · 0.65
showMethod · 0.45

Tested by

no test coverage detected