xstate 4.29.0 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/StateNode.js CHANGED
@@ -441,9 +441,10 @@ function () {
441
441
 
442
442
 
443
443
  StateNode.prototype.resolveState = function (state) {
444
- var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(state.value)));
445
- return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
446
- value: this.resolve(state.value),
444
+ var stateFromConfig = state instanceof State.State ? state : State.State.create(state);
445
+ var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(stateFromConfig.value)));
446
+ return new State.State(_tslib.__assign(_tslib.__assign({}, stateFromConfig), {
447
+ value: this.resolve(stateFromConfig.value),
447
448
  configuration: configuration,
448
449
  done: stateUtils.isInFinalState(configuration, this),
449
450
  tags: stateUtils.getTagsFromConfiguration(configuration)
@@ -1145,6 +1146,9 @@ function () {
1145
1146
  });
1146
1147
 
1147
1148
  StateNode.prototype.getInitialState = function (stateValue, context) {
1149
+ this._init(); // TODO: this should be in the constructor (see note in constructor)
1150
+
1151
+
1148
1152
  var configuration = this.getStateNodes(stateValue);
1149
1153
  return this.resolveTransition({
1150
1154
  configuration: configuration,
@@ -1162,9 +1166,6 @@ function () {
1162
1166
  * entering the initial state.
1163
1167
  */
1164
1168
  get: function () {
1165
- this._init(); // TODO: this should be in the constructor (see note in constructor)
1166
-
1167
-
1168
1169
  var initialStateValue = this.initialStateValue;
1169
1170
 
1170
1171
  if (!initialStateValue) {
package/lib/actions.js CHANGED
@@ -292,6 +292,9 @@ var assign = function (assignment) {
292
292
  assignment: assignment
293
293
  };
294
294
  };
295
+ function isActionObject(action) {
296
+ return typeof action === 'object' && 'type' in action;
297
+ }
295
298
  /**
296
299
  * Returns an event type that represents an implicit event that
297
300
  * is sent after the specified `delay`.
@@ -516,6 +519,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
516
519
  return [resolvedActions, updatedContext];
517
520
  }
518
521
 
522
+ exports.actionTypes = actionTypes;
519
523
  exports.after = after;
520
524
  exports.assign = assign;
521
525
  exports.cancel = cancel;
@@ -527,6 +531,7 @@ exports.escalate = escalate;
527
531
  exports.forwardTo = forwardTo;
528
532
  exports.getActionFunction = getActionFunction;
529
533
  exports.initEvent = initEvent;
534
+ exports.isActionObject = isActionObject;
530
535
  exports.log = log;
531
536
  exports.pure = pure;
532
537
  exports.raise = raise;
package/lib/index.d.ts CHANGED
@@ -4,29 +4,11 @@ import { StateNode } from './StateNode';
4
4
  import { State } from './State';
5
5
  import { Machine, createMachine } from './Machine';
6
6
  import { Actor } from './Actor';
7
- import { raise, send, sendParent, sendTo, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
7
+ import * as actions from './actions';
8
8
  import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
9
9
  import { matchState } from './match';
10
10
  import { createSchema, t } from './schema';
11
- declare const actions: {
12
- raise: typeof raise;
13
- send: typeof send;
14
- sendParent: typeof sendParent;
15
- sendTo: typeof sendTo;
16
- sendUpdate: typeof sendUpdate;
17
- log: typeof log;
18
- cancel: (sendId: string | number) => import("./types").CancelAction;
19
- start: typeof start;
20
- stop: typeof stop;
21
- assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
22
- after: typeof after;
23
- done: typeof done;
24
- respond: typeof respond;
25
- forwardTo: typeof forwardTo;
26
- escalate: typeof escalate;
27
- choose: typeof choose;
28
- pure: typeof pure;
29
- };
11
+ declare const assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>, send: typeof actions.send, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke;
30
12
  export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
31
13
  export * from './types';
32
14
  export * from './typegenTypes';
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var utils = require('./utils.js');
6
6
  var mapState = require('./mapState.js');
7
7
  var types = require('./types.js');
8
- var actions$1 = require('./actions.js');
8
+ var actions = require('./actions.js');
9
9
  var State = require('./State.js');
10
10
  var StateNode = require('./StateNode.js');
11
11
  var Machine = require('./Machine.js');
@@ -13,25 +13,12 @@ var interpreter = require('./interpreter.js');
13
13
  var match = require('./match.js');
14
14
  var schema = require('./schema.js');
15
15
 
16
- var actions = {
17
- raise: actions$1.raise,
18
- send: actions$1.send,
19
- sendParent: actions$1.sendParent,
20
- sendTo: actions$1.sendTo,
21
- sendUpdate: actions$1.sendUpdate,
22
- log: actions$1.log,
23
- cancel: actions$1.cancel,
24
- start: actions$1.start,
25
- stop: actions$1.stop,
26
- assign: actions$1.assign,
27
- after: actions$1.after,
28
- done: actions$1.done,
29
- respond: actions$1.respond,
30
- forwardTo: actions$1.forwardTo,
31
- escalate: actions$1.escalate,
32
- choose: actions$1.choose,
33
- pure: actions$1.pure
34
- };
16
+ var assign = actions.assign,
17
+ send = actions.send,
18
+ sendParent = actions.sendParent,
19
+ sendUpdate = actions.sendUpdate,
20
+ forwardTo = actions.forwardTo,
21
+ doneInvoke = actions.doneInvoke;
35
22
 
36
23
  exports.matchesState = utils.matchesState;
37
24
  exports.mapState = mapState.mapState;
@@ -47,12 +34,7 @@ Object.defineProperty(exports, 'SpecialTargets', {
47
34
  return types.SpecialTargets;
48
35
  }
49
36
  });
50
- exports.assign = actions$1.assign;
51
- exports.doneInvoke = actions$1.doneInvoke;
52
- exports.forwardTo = actions$1.forwardTo;
53
- exports.send = actions$1.send;
54
- exports.sendParent = actions$1.sendParent;
55
- exports.sendUpdate = actions$1.sendUpdate;
37
+ exports.actions = actions;
56
38
  exports.State = State.State;
57
39
  exports.StateNode = StateNode.StateNode;
58
40
  exports.Machine = Machine.Machine;
@@ -69,4 +51,9 @@ exports.spawn = interpreter.spawn;
69
51
  exports.matchState = match.matchState;
70
52
  exports.createSchema = schema.createSchema;
71
53
  exports.t = schema.t;
72
- exports.actions = actions;
54
+ exports.assign = assign;
55
+ exports.doneInvoke = doneInvoke;
56
+ exports.forwardTo = forwardTo;
57
+ exports.send = send;
58
+ exports.sendParent = sendParent;
59
+ exports.sendUpdate = sendUpdate;
@@ -1,6 +1,6 @@
1
- /// <reference types="node" />
2
1
  import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
3
2
  import { State } from './State';
3
+ import { StateConfig } from '.';
4
4
  import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
5
5
  export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
6
6
  value: any;
@@ -37,10 +37,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
37
37
  static defaultOptions: {
38
38
  execute: boolean;
39
39
  deferEvents: boolean;
40
- clock: {
41
- setTimeout: (fn: any, ms: any) => NodeJS.Timeout;
42
- clearTimeout: (id: any) => void;
43
- };
40
+ clock: Clock;
44
41
  logger: any;
45
42
  devTools: boolean;
46
43
  };
@@ -131,12 +128,12 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
131
128
  /**
132
129
  * Alias for Interpreter.prototype.start
133
130
  */
134
- init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | undefined) => this;
131
+ init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | undefined) => this;
135
132
  /**
136
133
  * Starts the interpreter from the given state, or the initial state.
137
134
  * @param initialState The state to start the statechart from
138
135
  */
139
- start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateValue): this;
136
+ start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
140
137
  /**
141
138
  * Stops the interpreter and unsubscribe all listeners.
142
139
  *
@@ -462,7 +462,7 @@ function () {
462
462
  this.initialized = true;
463
463
  this.status = exports.InterpreterStatus.Running;
464
464
  var resolvedState = initialState === undefined ? this.initialState : serviceScope.provide(this, function () {
465
- return State.isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.State.from(initialState, _this.machine.context));
465
+ return State.isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.State.from(initialState, _this.machine.context));
466
466
  });
467
467
 
468
468
  if (this.options.devTools) {
package/lib/types.d.ts CHANGED
@@ -564,6 +564,7 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
564
564
  history: 'shallow' | 'deep';
565
565
  target: StateValue | undefined;
566
566
  }
567
+ /** @ts-ignore TS complains about withConfig & withContext not being compatible here when extending StateNode */
567
568
  export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
568
569
  value: any;
569
570
  context: TContext;
@@ -572,12 +573,19 @@ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent
572
573
  states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
573
574
  withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
574
575
  withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, TResolvedTypesMeta>;
576
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
575
577
  __TContext: TContext;
578
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
576
579
  __TStateSchema: TStateSchema;
580
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
577
581
  __TEvent: TEvent;
582
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
578
583
  __TTypestate: TTypestate;
584
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
579
585
  __TAction: TAction;
586
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
580
587
  __TServiceMap: TServiceMap;
588
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
581
589
  __TResolvedTypesMeta: TResolvedTypesMeta;
582
590
  }
583
591
  export declare type StateFrom<T extends StateMachine<any, any, any, any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any, any, any, any>)> = T extends StateMachine<any, any, any, any, any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any, any, any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.29.0",
3
+ "version": "4.30.0",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",