|
@@ -47,6 +47,13 @@ export interface IComponent<
|
|
mounted?: (this: Component) => any;
|
|
mounted?: (this: Component) => any;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Components also are records, because they carry any type of data.
|
|
|
|
+ */
|
|
|
|
+export interface Component extends Record<string, any> {
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
export class Component {
|
|
export class Component {
|
|
public static create<
|
|
public static create<
|
|
TMethods extends Record<string, CallableFunction>,
|
|
TMethods extends Record<string, CallableFunction>,
|
|
@@ -55,6 +62,11 @@ export class Component {
|
|
return new Component(component) as (Component & TMethods);
|
|
return new Component(component) as (Component & TMethods);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * The component parent to this component.
|
|
|
|
+ */
|
|
|
|
+ public $parent: Component|null = null;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* The state related to this component.
|
|
* The state related to this component.
|
|
*/
|
|
*/
|
|
@@ -75,8 +87,6 @@ export class Component {
|
|
*/
|
|
*/
|
|
public $refs: Record<string, HTMLElement> = {};
|
|
public $refs: Record<string, HTMLElement> = {};
|
|
|
|
|
|
- protected parser: DOMParser;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* If it's the first time that the component is being rendered.
|
|
* If it's the first time that the component is being rendered.
|
|
*/
|
|
*/
|
|
@@ -85,7 +95,7 @@ export class Component {
|
|
/**
|
|
/**
|
|
* The virtual DOM renderer instance.
|
|
* The virtual DOM renderer instance.
|
|
*/
|
|
*/
|
|
- protected renderer = new Renderer(this);
|
|
|
|
|
|
+ public renderer = new Renderer(this);
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
/**
|
|
/**
|
|
@@ -139,6 +149,19 @@ export class Component {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * The root component.
|
|
|
|
+ */
|
|
|
|
+ public get $root() {
|
|
|
|
+ let parent = this.$parent;
|
|
|
|
+
|
|
|
|
+ while(parent?.$parent !== null) {
|
|
|
|
+ parent = parent?.$parent;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return parent;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Enqueues a function to be executed in the next queue tick.
|
|
* Enqueues a function to be executed in the next queue tick.
|
|
* @param callback — The callback to be executed.
|
|
* @param callback — The callback to be executed.
|