UNPKG

2.07 kBTypeScriptView Raw
1import { Spawner } from "../spawn.js";
2import type { ActionArgs, AnyEventObject, Assigner, EventObject, LowInfer, MachineContext, ParameterizedObject, PropertyAssigner, ProvidedActor, ActionFunction } from "../types.js";
3export interface AssignArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor> extends ActionArgs<TContext, TExpressionEvent, TEvent> {
4 spawn: Spawner<TActor>;
5}
6export interface AssignAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> {
7 (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
8 _out_TActor?: TActor;
9}
10/**
11 * Updates the current context of the machine.
12 *
13 * @example
14 *
15 * ```ts
16 * import { createMachine, assign } from 'xstate';
17 *
18 * const countMachine = createMachine({
19 * context: {
20 * count: 0,
21 * message: ''
22 * },
23 * on: {
24 * inc: {
25 * actions: assign({
26 * count: ({ context }) => context.count + 1
27 * })
28 * },
29 * updateMessage: {
30 * actions: assign(({ context, event }) => {
31 * return {
32 * message: event.message.trim()
33 * };
34 * })
35 * }
36 * }
37 * });
38 * ```
39 *
40 * @param assignment An object that represents the partial context to update, or
41 * a function that returns an object that represents the partial context to
42 * update.
43 */
44export declare function assign<TContext extends MachineContext, TExpressionEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
45TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent, TParams, TEvent, TActor> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent, TParams, TEvent, TActor>): ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, never, never, never, never>;