Skip to content

Commit 50499ae

Browse files
committed
[WIP] temp
1 parent cb2b738 commit 50499ae

File tree

6 files changed

+30
-56
lines changed

6 files changed

+30
-56
lines changed

src/runtime/component_node.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
106106
value: undefined,
107107
compute: () => this.render(false),
108108
sources: new Set<Atom>(),
109-
state: ComputationState.STALE,
109+
state: ComputationState.EXECUTED,
110110
};
111111
const defaultProps = C.defaultProps;
112112
props = Object.assign({}, props);
@@ -138,10 +138,11 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
138138
}
139139
const component = this.component;
140140
try {
141-
const previousComputation = getCurrentComputation();
142-
setComputation(undefined);
143-
await Promise.all(this.willStart.map((f) => withoutReactivity(() => f.call(component))));
144-
setComputation(previousComputation);
141+
let prom: Promise<any[]>;
142+
withoutReactivity(() => {
143+
prom = Promise.all(this.willStart.map((f) => f.call(component)));
144+
});
145+
await prom!;
145146
} catch (e) {
146147
this.app.handleError({ node: this, error: e });
147148
return;
@@ -256,11 +257,11 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
256257
applyDefaultProps(props, defaultProps);
257258
}
258259

259-
const previouwsComputation = getCurrentComputation();
260-
setComputation(undefined);
261-
await Promise.all(this.willUpdateProps.map((f) => f.call(component, props)));
262-
setComputation(previouwsComputation);
263-
260+
let prom: Promise<any[]>;
261+
withoutReactivity(() => {
262+
prom = Promise.all(this.willUpdateProps.map((f) => f.call(component, props)));
263+
});
264+
await prom!;
264265
if (fiber !== this.fiber) {
265266
return;
266267
}

src/runtime/fibers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fibersInError } from "./error_handling";
44
import { OwlError } from "../common/owl_error";
55
import { STATUS } from "./status";
66
import { runWithComputation } from "./signals";
7-
import { ComputationState } from "../common/types";
7+
// import { ComputationState } from "../common/types";
88

99
export function makeChildFiber(node: ComponentNode, parent: Fiber): Fiber {
1010
let current = node.fiber;
@@ -143,7 +143,7 @@ export class Fiber {
143143
} catch (e) {
144144
node.app.handleError({ node, error: e });
145145
}
146-
node.signalComputation.state = ComputationState.EXECUTED;
146+
// node.signalComputation.state = ComputationState.EXECUTED;
147147
});
148148
root.setCounter(root.counter - 1);
149149
}

src/runtime/signals.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export function effect<T>(fn: () => T, opts?: Opts) {
3838
return fn();
3939
},
4040
sources: new Set(),
41+
childrenEffect: [],
4142
name: opts?.name,
4243
};
43-
effectComputation.childrenEffect = [];
4444
CurrentComputation?.childrenEffect?.push?.(effectComputation);
4545
updateComputation(effectComputation);
4646

@@ -54,20 +54,20 @@ export function effect<T>(fn: () => T, opts?: Opts) {
5454
CurrentComputation = previousComputation!;
5555
};
5656
}
57-
export function computed<T>(fn: () => T, opts?: Opts) {
58-
// todo: handle cleanup
59-
let computedComputation: Computation = {
60-
state: ComputationState.STALE,
61-
sources: new Set(),
62-
isEager: true,
63-
compute: () => {
64-
return fn();
65-
},
66-
value: undefined,
67-
name: opts?.name,
68-
};
69-
updateComputation(computedComputation);
70-
}
57+
// export function computed<T>(fn: () => T, opts?: Opts) {
58+
// // todo: handle cleanup
59+
// let computedComputation: Computation = {
60+
// state: ComputationState.STALE,
61+
// sources: new Set(),
62+
// isEager: true,
63+
// compute: () => {
64+
// return fn();
65+
// },
66+
// value: undefined,
67+
// name: opts?.name,
68+
// };
69+
// updateComputation(computedComputation);
70+
// }
7171
export function derived<T>(fn: () => T, opts?: Opts): () => T {
7272
// todo: handle cleanup
7373
let derivedComputation: Derived<any, any>;

tests/components/__snapshots__/props_validation.test.ts.snap

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -880,33 +880,6 @@ exports[`props validation props are validated whenever component is updated 2`]
880880
}"
881881
`;
882882

883-
exports[`props validation props validation does not cause additional subscription 1`] = `
884-
"function anonymous(app, bdom, helpers
885-
) {
886-
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
887-
const comp1 = app.createComponent(\`Child\`, true, false, false, [\\"obj\\"]);
888-
889-
return function template(ctx, node, key = \\"\\") {
890-
const props1 = {obj: ctx['obj']};
891-
helpers.validateProps(\`Child\`, props1, this);
892-
const b2 = comp1(props1, key + \`__1\`, node, this, null);
893-
const b3 = text(ctx['obj'].otherValue);
894-
return multi([b2, b3]);
895-
}
896-
}"
897-
`;
898-
899-
exports[`props validation props validation does not cause additional subscription 2`] = `
900-
"function anonymous(app, bdom, helpers
901-
) {
902-
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
903-
904-
return function template(ctx, node, key = \\"\\") {
905-
return text(ctx['props'].obj.value);
906-
}
907-
}"
908-
`;
909-
910883
exports[`props validation props: list of strings 1`] = `
911884
"function anonymous(app, bdom, helpers
912885
) {

tests/components/lifecycle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ describe("lifecycle hooks", () => {
995995
`);
996996
});
997997

998-
test.only("onWillRender", async () => {
998+
test("onWillRender", async () => {
999999
const def = makeDeferred();
10001000

10011001
class Child extends Component {

tests/components/props_validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeTestFixture, nextAppError, nextTick, snapshotEverything } from "../helpers";
2-
import { Component, onError, xml, mount, OwlError, useState } from "../../src";
2+
import { Component, onError, xml, mount, OwlError } from "../../src";
33
import { App } from "../../src/runtime/app";
44
import { validateProps } from "../../src/runtime/template_helpers";
55
import { Schema } from "../../src/runtime/validation";

0 commit comments

Comments
 (0)