This commit is contained in:
Géry Debongnie
2021-11-20 10:18:42 +01:00
parent 9c2523e3ce
commit 89d6b8b7dd
2 changed files with 10 additions and 3 deletions
+8 -1
View File
@@ -1,3 +1,4 @@
import { useState } from "../reactivity";
import type { App, Env } from "../app/app"; import type { App, Env } from "../app/app";
import { BDom, VNode } from "../blockdom"; import { BDom, VNode } from "../blockdom";
import { Component, Props } from "./component"; import { Component, Props } from "./component";
@@ -15,6 +16,8 @@ import { applyDefaultProps } from "./props_validation";
import { STATUS } from "./status"; import { STATUS } from "./status";
import { applyStyles } from "./style"; import { applyStyles } from "./style";
let currentNode: ComponentNode | null = null;
function arePropsDifferent(props1: Props, props2: Props): boolean { function arePropsDifferent(props1: Props, props2: Props): boolean {
for (let k in props1) { for (let k in props1) {
if (props1[k] !== props2[k]) { if (props1[k] !== props2[k]) {
@@ -75,7 +78,6 @@ export function component(
// Component VNode // Component VNode
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
let currentNode: ComponentNode | null = null;
export function getCurrent(): ComponentNode | null { export function getCurrent(): ComponentNode | null {
return currentNode; return currentNode;
@@ -117,6 +119,11 @@ export class ComponentNode<T extends typeof Component = typeof Component>
applyDefaultProps(props, C); applyDefaultProps(props, C);
const env = (parent && parent.childEnv) || app.env; const env = (parent && parent.childEnv) || app.env;
this.childEnv = env; this.childEnv = env;
if (props) {
props = useState(props);
} else {
console.trace()
}
this.component = new C(props, env, this) as any; this.component = new C(props, env, this) as any;
this.renderFn = app.getTemplate(C.template).bind(this.component, this.component, this); this.renderFn = app.getTemplate(C.template).bind(this.component, this.component, this);
if (C.style) { if (C.style) {
+2 -2
View File
@@ -53,7 +53,7 @@ describe("rendering semantics", () => {
class Child extends Component { class Child extends Component {
static template = xml`child`; static template = xml`child`;
setup() { setup() {
onRender(() => childN++); onRendered(() => childN++);
} }
} }
@@ -66,7 +66,7 @@ describe("rendering semantics", () => {
state = { value: "A" }; state = { value: "A" };
setup() { setup() {
onRender(() => parentN++); onRendered(() => parentN++);
} }
} }