xstate
Version:
Finite State Machines and Statecharts for the Modern Web.
34 lines (32 loc) • 1.64 kB
TypeScript
import { EventObject, MachineContext, ActionArgs, ParameterizedObject } from "../types.js";
type ResolvableSendId<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = string | ((args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => string);
export interface CancelAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> {
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
}
/**
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The canceled `sendTo(...)` action
* will not send its event or execute, unless the `delay` has already elapsed before `cancel(...)` is called.
*
* @param sendId The `id` of the `sendTo(...)` action to cancel.
*
* @example
```ts
import { createMachine, sendTo, cancel } from 'xstate';
const machine = createMachine({
// ...
on: {
sendEvent: {
actions: sendTo('some-actor', { type: 'someEvent' }, {
id: 'some-id',
delay: 1000
})
},
cancelEvent: {
actions: cancel('some-id')
}
}
});
```
*/
export declare function cancel<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject>(sendId: ResolvableSendId<TContext, TExpressionEvent, TParams, TEvent>): CancelAction<TContext, TExpressionEvent, TParams, TEvent>;
export {};