foldkit 0.153.0 → 0.154.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -108,12 +108,13 @@ export const refresh = (refreshable) => model => pipe(refreshable.read(model), O
108
108
  * Command that produces the child's Message, such as an animating
109
109
  * component's overridable leave Command.
110
110
  *
111
- * A parent that is itself a Submodel passes a
112
- * {@link ChildFoldWithParentOutMessage} and receives a
113
- * {@link FoldWithOutMessage}, whose results may include the parent's own
114
- * OutMessage. Add `toParentOutMessage` only when it forwards at least one
115
- * child OutMessage from the current Submodel to its parent. Omit
116
- * `toParentOutMessage` when the local `foldOutMessage` handles every variant.
111
+ * A parent that is itself a Submodel receives a
112
+ * {@link FoldWithOutMessage} when `foldOutMessage` emits a derived parent
113
+ * OutMessage. Add `toParentOutMessage` only when at least one child OutMessage
114
+ * should continue to the current Submodel's parent. When provided,
115
+ * `foldOutMessage` still handles forwarded variants locally. A derived
116
+ * OutMessage replaces the one-to-one lift for the dispatch. When the Step
117
+ * emits nothing, the lift runs as usual.
117
118
  *
118
119
  * An entry point that takes nothing but the child Model, such as
119
120
  * `Dialog.close`, has no input to pass: fold it with
@@ -153,21 +154,18 @@ const runChildFold = (childFold, context, model, input) => pipe(model, childFold
153
154
  const update = childFold.foldOutMessage === undefined ||
154
155
  childUpdate.outMessage === undefined
155
156
  ? { model: modelWithChild, commands: mappedCommands }
156
- : combine(modelWithChild, [
157
- stepModel => ({
158
- model: stepModel,
159
- commands: mappedCommands,
160
- }),
161
- childFold.foldOutMessage(childUpdate.outMessage, context),
162
- ]);
163
- if (childFold.toParentOutMessage === undefined) {
157
+ : appendOutMessageStep(childFold.foldOutMessage, childUpdate.outMessage, context, modelWithChild, mappedCommands);
158
+ if (update.outMessage !== undefined) {
164
159
  return update;
165
160
  }
166
- if (childUpdate.outMessage === undefined) {
161
+ if (childFold.toParentOutMessage === undefined ||
162
+ childUpdate.outMessage === undefined) {
167
163
  return update;
168
164
  }
169
165
  const parentOutMessage = childFold.toParentOutMessage(childUpdate.outMessage);
170
- return withOutMessage(update, parentOutMessage);
166
+ return parentOutMessage === undefined
167
+ ? update
168
+ : { ...update, outMessage: parentOutMessage };
171
169
  },
172
170
  }));
173
171
  /** Folds a child entry point that takes nothing but the child Model, and
@@ -199,13 +197,19 @@ const runChildFold = (childFold, context, model, input) => pipe(model, childFold
199
197
  * `liftCommands` bound to this config's `toParentMessage`, for a Command the
200
198
  * Step returns whose result is the child's Message.
201
199
  *
202
- * A parent that is itself a Submodel adds `toParentOutMessage` when it
203
- * forwards at least one child OutMessage to its own parent and receives a
204
- * {@link StepWithOutMessage}, just as the input-taking {@link foldChild}
205
- * returns a {@link FoldWithOutMessage}. When no child OutMessage is
206
- * forwarded, omit the lift and use the plain Step directly. Local handling
207
- * through `foldOutMessage` is independent of forwarding. */
200
+ * A parent that is itself a Submodel receives a
201
+ * {@link StepWithOutMessage} when `foldOutMessage` emits a derived parent
202
+ * OutMessage. Add `toParentOutMessage` only when at least one child OutMessage
203
+ * should continue to the current Submodel's parent. When provided,
204
+ * `foldOutMessage` still handles forwarded variants locally. A derived
205
+ * OutMessage replaces the one-to-one lift for the dispatch. When the Step
206
+ * emits nothing, the lift runs as usual. */
208
207
  export const foldChildStep = (childFold) => {
209
208
  const context = makeFoldContext(childFold.toParentMessage);
210
209
  return (model) => runChildFold(childFold, context, model, undefined);
211
210
  };
211
+ const appendOutMessageStep = (foldOutMessage, outMessage, context, modelWithChild, mappedCommands) => {
212
+ const outMessageFold = foldOutMessage(outMessage, context)(modelWithChild);
213
+ const commands = [...mappedCommands, ...(outMessageFold.commands ?? [])];
214
+ return { ...outMessageFold, commands };
215
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit",
3
- "version": "0.153.0",
3
+ "version": "0.154.0",
4
4
  "description": "A TypeScript frontend framework, built on Effect and architected like Elm",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",