From 0429f95c5644506031799e404ffb8083f1f9a5b7 Mon Sep 17 00:00:00 2001 From: eyelidlessness Date: Wed, 3 Apr 2024 10:02:04 -0700 Subject: [PATCH] =?UTF-8?q?Fix:=20`childrenState`=20must=20be=20defined=20?= =?UTF-8?q?before=20other=20reactive=20node=20state=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … specifically, before calling `createComputedExpression` or anything else that may exercise the `SubscribableDependency` interface. TODO(?): detect this condition and throw a more meaningful error? --- packages/xforms-engine/src/instance/Group.ts | 4 +++- packages/xforms-engine/src/instance/RepeatInstance.ts | 7 ++++--- packages/xforms-engine/src/instance/Root.ts | 6 ++++-- packages/xforms-engine/src/instance/Subtree.ts | 4 +++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/xforms-engine/src/instance/Group.ts b/packages/xforms-engine/src/instance/Group.ts index 76d07ef0a..1d6d9d505 100644 --- a/packages/xforms-engine/src/instance/Group.ts +++ b/packages/xforms-engine/src/instance/Group.ts @@ -42,6 +42,9 @@ export class Group super(parent, definition); const childrenState = createChildrenState(this); + + this.childrenState = childrenState; + const state = createSharedNodeState( this.scope, { @@ -58,7 +61,6 @@ export class Group } ); - this.childrenState = childrenState; this.state = state; this.engineState = state.engineState; this.currentState = materializeCurrentStateChildren(state.currentState, childrenState); diff --git a/packages/xforms-engine/src/instance/RepeatInstance.ts b/packages/xforms-engine/src/instance/RepeatInstance.ts index 9818d6285..03f1e4da0 100644 --- a/packages/xforms-engine/src/instance/RepeatInstance.ts +++ b/packages/xforms-engine/src/instance/RepeatInstance.ts @@ -58,6 +58,10 @@ export class RepeatInstance ) { super(parent, definition); + const childrenState = createChildrenState(this); + + this.childrenState = childrenState; + options.precedingPrimaryInstanceNode.after(this.contextNode); const { precedingInstance } = options; @@ -66,8 +70,6 @@ export class RepeatInstance const [currentIndex, setCurrentIndex] = createSignal(initialIndex); this.currentIndex = currentIndex; - - const childrenState = createChildrenState(this); const state = createSharedNodeState( this.scope, { @@ -84,7 +86,6 @@ export class RepeatInstance } ); - this.childrenState = childrenState; this.state = state; this.engineState = state.engineState; this.currentState = materializeCurrentStateChildren(state.currentState, childrenState); diff --git a/packages/xforms-engine/src/instance/Root.ts b/packages/xforms-engine/src/instance/Root.ts index e3546cea5..efade67ae 100644 --- a/packages/xforms-engine/src/instance/Root.ts +++ b/packages/xforms-engine/src/instance/Root.ts @@ -150,6 +150,10 @@ export class Root ) { super(engineConfig, null, definition); + const childrenState = createChildrenState(this); + + this.childrenState = childrenState; + const reference = definition.nodeset; this.rootReference = reference; @@ -158,7 +162,6 @@ export class Root const evaluator = instanceDOM.primaryInstanceEvaluator; const { translations } = evaluator; const { defaultLanguage, languages } = getInitialLanguageState(translations); - const childrenState = createChildrenState(this); const state = createSharedNodeState( this.scope, { @@ -178,7 +181,6 @@ export class Root } ); - this.childrenState = childrenState; this.state = state; this.engineState = state.engineState; this.currentState = materializeCurrentStateChildren(state.currentState, childrenState); diff --git a/packages/xforms-engine/src/instance/Subtree.ts b/packages/xforms-engine/src/instance/Subtree.ts index eccb0c173..2d5a00267 100644 --- a/packages/xforms-engine/src/instance/Subtree.ts +++ b/packages/xforms-engine/src/instance/Subtree.ts @@ -39,6 +39,9 @@ export class Subtree super(parent, definition); const childrenState = createChildrenState(this); + + this.childrenState = childrenState; + const state = createSharedNodeState( this.scope, { @@ -55,7 +58,6 @@ export class Subtree } ); - this.childrenState = childrenState; this.state = state; this.engineState = state.engineState; this.currentState = materializeCurrentStateChildren(state.currentState, childrenState);