MCPcopy Create free account
hub / github.com/adearriba/ShopifyCheckoutJS / BaseComponent

Class BaseComponent

src/Components/BaseComponent.js:1–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1export class BaseComponent extends HTMLDivElement{
2 constructor(args = null)
3 {
4 let componentType = 'component';
5 if(args)
6 {
7 componentType = args.type ?? 'component';
8 }
9
10 let element = document.createElement('div');
11 Object.setPrototypeOf(element, BaseComponent.prototype);
12
13 return Object.assign(element, {
14 componentType
15 });
16 }
17
18 /**
19 * Insert the current component after the specified component parameter.
20 * @param {BaseComponent} component
21 * @throws {TypeError} Object trying to add is not a component
22 */
23 insertAfter(component){
24 if(!component || !(component instanceof BaseComponent)) throw TypeError('Object trying to add is not a component.');
25 this.insertAdjacentElement('afterend', component);
26 }
27
28 /**
29 * Insert the current component before the specified component parameter.
30 * @param {BaseComponent} component
31 * @throws {TypeError} Object trying to add is not a component
32 */
33 insertBefore(component){
34 if(!component || !(component instanceof BaseComponent)) throw TypeError('Object trying to add is not a component.');
35 this.insertAdjacentElement('beforebegin', component);
36 }
37}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected