@@ -2,7 +2,6 @@ import { OwlError } from "../common/owl_error";
22import { Atom , Computation , ComputationState } from "../common/types" ;
33import type { App , Env } from "./app" ;
44import { BDom , VNode } from "./blockdom" ;
5- import { makeTaskContext , TaskContext } from "./cancellableContext" ;
65import { Component , ComponentConstructor , Props } from "./component" ;
76import { fibersInError } from "./error_handling" ;
87import { Fiber , makeChildFiber , makeRootFiber , MountFiber , MountOptions } from "./fibers" ;
@@ -44,7 +43,6 @@ function applyDefaultProps<P extends object>(props: P, defaultProps: Partial<P>)
4443// Integration with reactivity system (useState)
4544// -----------------------------------------------------------------------------
4645
47- // const batchedRenderFunctions = new WeakMap<ComponentNode, Callback>();
4846/**
4947 * Creates a reactive object that will be observed by the current component.
5048 * Reading data from the returned object (eg during rendering) will cause the
@@ -90,7 +88,6 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
9088 willPatch : LifecycleHook [ ] = [ ] ;
9189 patched : LifecycleHook [ ] = [ ] ;
9290 willDestroy : LifecycleHook [ ] = [ ] ;
93- taskContext : TaskContext ;
9491 signalComputation : Computation ;
9592
9693 constructor (
@@ -105,15 +102,11 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
105102 this . parent = parent ;
106103 this . props = props ;
107104 this . parentKey = parentKey ;
108- this . taskContext = makeTaskContext ( ) ;
109105 this . signalComputation = {
110- // data: this,
111106 value : undefined ,
112- compute : ( ) => {
113- this . render ( false ) ;
114- } ,
107+ compute : ( ) => this . render ( false ) ,
115108 sources : new Set < Atom > ( ) ,
116- state : ComputationState . EXECUTED ,
109+ state : ComputationState . STALE ,
117110 } ;
118111 const defaultProps = C . defaultProps ;
119112 props = Object . assign ( { } , props ) ;
@@ -122,19 +115,13 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
122115 }
123116 const env = ( parent && parent . childEnv ) || app . env ;
124117 this . childEnv = env ;
125- // for (const key in props) {
126- // const prop = props[key];
127- // if (prop && typeof prop === "object" && targets.has(prop)) {
128- // props[key] = useState(prop);
129- // }
130- // }
131- const currentContext = getCurrentComputation ( ) ;
118+ const previousComputation = getCurrentComputation ( ) ;
132119 setComputation ( this . signalComputation ) ;
133120 this . component = new C ( props , env , this ) ;
134121 const ctx = Object . assign ( Object . create ( this . component ) , { this : this . component } ) ;
135122 this . renderFn = app . getTemplate ( C . template ) . bind ( this . component , ctx , this ) ;
136123 this . component . setup ( ) ;
137- setComputation ( currentContext ) ;
124+ setComputation ( previousComputation ) ;
138125 currentNode = null ;
139126 }
140127
@@ -151,11 +138,10 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
151138 }
152139 const component = this . component ;
153140 try {
154- let prom : Promise < any [ ] > ;
155- withoutReactivity ( ( ) => {
156- prom = Promise . all ( this . willStart . map ( ( f ) => f . call ( component ) ) ) ;
157- } ) ;
158- await prom ! ;
141+ const previousComputation = getCurrentComputation ( ) ;
142+ setComputation ( undefined ) ;
143+ await Promise . all ( this . willStart . map ( ( f ) => withoutReactivity ( ( ) => f . call ( component ) ) ) ) ;
144+ setComputation ( previousComputation ) ;
159145 } catch ( e ) {
160146 this . app . handleError ( { node : this , error : e } ) ;
161147 return ;
@@ -270,11 +256,11 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
270256 applyDefaultProps ( props , defaultProps ) ;
271257 }
272258
273- let prom : Promise < any [ ] > ;
274- withoutReactivity ( ( ) => {
275- prom = Promise . all ( this . willUpdateProps . map ( ( f ) => f . call ( component , props ) ) ) ;
276- } ) ;
277- await prom ! ;
259+ const previouwsComputation = getCurrentComputation ( ) ;
260+ setComputation ( undefined ) ;
261+ await Promise . all ( this . willUpdateProps . map ( ( f ) => f . call ( component , props ) ) ) ;
262+ setComputation ( previouwsComputation ) ;
263+
278264 if ( fiber !== this . fiber ) {
279265 return ;
280266 }
@@ -391,9 +377,4 @@ export class ComponentNode<P extends Props = any, E = any> implements VNode<Comp
391377 get name ( ) : string {
392378 return this . component . constructor . name ;
393379 }
394-
395- // get subscriptions(): ReturnType<typeof getSubscriptions> {
396- // const render = batchedRenderFunctions.get(this);
397- // return render ? getSubscriptions(render) : [];
398- // }
399380}
0 commit comments