Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { effectParams } from './EffectCreator'

describe('effectParams', () => {
test('tags the call with the calling procedure', () => {
expect(effectParams({ actionId: 'a' }, 'procedure')).toEqual({
actionId: 'a',
eventId: 'procedure',
})
})

test('keeps the event id an action run names', () => {
expect(
effectParams({ actionId: 'a', eventId: 'form' }, 'procedure'),
).toEqual({ actionId: 'a', eventId: 'form' })
})

test('sends no event id outside a procedure', () => {
expect(JSON.stringify(effectParams({ actionId: 'a' }, null))).toBe(
'{"actionId":"a"}',
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export type EffectContext = {
constRetry?: () => void
}

/** The effect call's params, tagged with the calling procedure's event id. An `eventId` the effect names itself wins. */
export function effectParams(
params: Record<string, unknown>,
eventId: string | null,
): Record<string, unknown> {
return { eventId: eventId ?? undefined, ...params }
}

const rpcRoundFor =
(eventId: string | null) =>
<K extends T.EffectMethod | 'clearCallbacks'>(
Expand All @@ -58,7 +66,7 @@ const rpcRoundFor =
JSON.stringify({
id,
method,
params: { ...params, eventId: eventId ?? undefined },
params: effectParams(params, eventId),
}) + '\n',
)
})
Expand Down
Loading