(
target: SendToActionTarget<
TContext,
TExpressionEvent,
TParams,
AnyActorRef,
TEvent
>,
options?: SendToActionOptions<
TContext,
TExpressionEvent,
TParams,
TEvent,
TUsedDelay
>
)
| 334 | * @param options Options to pass into the send action creator. |
| 335 | */ |
| 336 | export function forwardTo< |
| 337 | TContext extends MachineContext, |
| 338 | TExpressionEvent extends EventObject, |
| 339 | TParams extends ParameterizedObject['params'] | undefined, |
| 340 | TEvent extends EventObject, |
| 341 | TDelay extends string = never, |
| 342 | TUsedDelay extends TDelay = never |
| 343 | >( |
| 344 | target: SendToActionTarget< |
| 345 | TContext, |
| 346 | TExpressionEvent, |
| 347 | TParams, |
| 348 | AnyActorRef, |
| 349 | TEvent |
| 350 | >, |
| 351 | options?: SendToActionOptions< |
| 352 | TContext, |
| 353 | TExpressionEvent, |
| 354 | TParams, |
| 355 | TEvent, |
| 356 | TUsedDelay |
| 357 | > |
| 358 | ) { |
| 359 | if (isDevelopment && (!target || typeof target === 'function')) { |
| 360 | const originalTarget = target; |
| 361 | target = (...args) => { |
| 362 | const resolvedTarget = |
| 363 | typeof originalTarget === 'function' |
| 364 | ? originalTarget(...args) |
| 365 | : originalTarget; |
| 366 | if (!resolvedTarget) { |
| 367 | throw new Error( |
| 368 | `Attempted to forward event to undefined actor. This risks an infinite loop in the sender.` |
| 369 | ); |
| 370 | } |
| 371 | return resolvedTarget; |
| 372 | }; |
| 373 | } |
| 374 | return sendTo< |
| 375 | TContext, |
| 376 | TExpressionEvent, |
| 377 | TParams, |
| 378 | AnyActorRef, |
| 379 | TEvent, |
| 380 | TDelay, |
| 381 | TUsedDelay |
| 382 | >(target, ({ event }: any) => event, options); |
| 383 | } |
| 384 | |
| 385 | export interface ExecutableSendToAction extends ExecutableActionObject { |
| 386 | type: 'xstate.sendTo'; |
no test coverage detected