Skip to content

Commit 74362e3

Browse files
Specialize childless machine runtimes (#47)
1 parent d602202 commit 74362e3

4 files changed

Lines changed: 375 additions & 303 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@typeonce/effect-machine": patch
3+
---
4+
5+
Skip child-registry allocation for statecharts that cannot invoke child processes, while preserving empty child lookup, observation, send, and stop behavior.

src/internal/machineProcess.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const makeProcessLogic: <
122122
) => {
123123
const hasInvokes = hasInvokeCapability(machine)
124124
return ({
125+
[internalRuntime.childlessProcess]: hasInvokes ? undefined : true,
125126
initial: (scope) =>
126127
internalRuntime.provideMachineRuntime(
127128
Effect.gen(function*() {
@@ -326,6 +327,7 @@ const makeProcessLogic: <
326327
return yield* Effect.fail(new ChildAlreadyExistsError({ id: invokeId }))
327328
}
328329
const logic = config.src()
330+
const processLogic = logic as internalRuntime.ProcessLogic<any, any, any, any, any, any>
329331
const sendParent = (event: unknown): Effect.Effect<void, StoppedError> =>
330332
isCurrentInvoke(key, token).pipe(
331333
Effect.flatMap((isCurrent) =>
@@ -334,6 +336,9 @@ const makeProcessLogic: <
334336
)
335337
yield* context.spawn(
336338
{
339+
...(processLogic[internalRuntime.childlessProcess] === true
340+
? { [internalRuntime.childlessProcess]: true as const }
341+
: undefined),
337342
initial: (childScope) => logic.initial({ ...childScope, sendParent }),
338343
run: (childContext) => logic.run({ ...childContext, sendParent })
339344
},

0 commit comments

Comments
 (0)