xstate 4.19.2 → 4.20.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/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # xstate
2
2
 
3
+ ## 4.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`28059b9f`](https://github.com/davidkpiano/xstate/commit/28059b9f09926d683d80b7d816f5b703c0667a9f) [#2197](https://github.com/davidkpiano/xstate/pull/2197) Thanks [@davidkpiano](https://github.com/davidkpiano)! - All spawned and invoked actors now have a `.getSnapshot()` method, which allows you to retrieve the latest value emitted from that actor. That value may be `undefined` if no value has been emitted yet.
8
+
9
+ ```js
10
+ const machine = createMachine({
11
+ context: {
12
+ promiseRef: null
13
+ },
14
+ initial: 'pending',
15
+ states: {
16
+ pending: {
17
+ entry: assign({
18
+ promiseRef: () => spawn(fetch(/* ... */), 'some-promise')
19
+ })
20
+ }
21
+ }
22
+ });
23
+
24
+ const service = interpret(machine)
25
+ .onTransition(state => {
26
+ // Read promise value synchronously
27
+ const resolvedValue = state.context.promiseRef?.getSnapshot();
28
+ // => undefined (if promise not resolved yet)
29
+ // => { ... } (resolved data)
30
+ })
31
+ .start();
32
+
33
+ // ...
34
+ ```
35
+
36
+ ### Patch Changes
37
+
38
+ - [`4ef03465`](https://github.com/davidkpiano/xstate/commit/4ef03465869e27dc878ec600661c9253d90f74f0) [#2240](https://github.com/davidkpiano/xstate/pull/2240) Thanks [@VanTanev](https://github.com/VanTanev)! - Preserve StateMachine type when .withConfig() and .withContext() modifiers are used on a machine.
39
+
3
40
  ## 4.19.2
4
41
 
5
42
  ### Patch Changes
package/es/StateNode.d.ts CHANGED
@@ -136,7 +136,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
136
136
  *
137
137
  * @param context Custom context (will override predefined context, not recursive)
138
138
  */
139
- withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent>;
139
+ withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
140
140
  /**
141
141
  * The well-structured state node definition.
142
142
  */
package/es/types.d.ts CHANGED
@@ -490,6 +490,8 @@ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent
490
490
  }> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
491
491
  id: string;
492
492
  states: StateNode<TContext, TStateSchema, TEvent>['states'];
493
+ withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
494
+ withContext(context: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
493
495
  }
494
496
  export declare type StateFrom<TMachine extends StateMachine<any, any, any>> = ReturnType<TMachine['transition']>;
495
497
  export interface ActionMap<TContext, TEvent extends EventObject> {
@@ -890,6 +892,9 @@ export interface SpawnedActorRef<TEvent extends EventObject, TEmitted = any> ext
890
892
  toJSON?: () => any;
891
893
  }
892
894
  export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? SpawnedActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
895
+ /**
896
+ * @deprecated
897
+ */
893
898
  state: State<TContext, TEvent, any, TTypestate>;
894
899
  } : T extends Promise<infer U> ? SpawnedActorRef<never, U> : never;
895
900
  export declare type AnyInterpreter = Interpreter<any, any, any, any>;
@@ -136,7 +136,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
136
136
  *
137
137
  * @param context Custom context (will override predefined context, not recursive)
138
138
  */
139
- withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent>;
139
+ withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
140
140
  /**
141
141
  * The well-structured state node definition.
142
142
  */
package/lib/types.d.ts CHANGED
@@ -490,6 +490,8 @@ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent
490
490
  }> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
491
491
  id: string;
492
492
  states: StateNode<TContext, TStateSchema, TEvent>['states'];
493
+ withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
494
+ withContext(context: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
493
495
  }
494
496
  export declare type StateFrom<TMachine extends StateMachine<any, any, any>> = ReturnType<TMachine['transition']>;
495
497
  export interface ActionMap<TContext, TEvent extends EventObject> {
@@ -890,6 +892,9 @@ export interface SpawnedActorRef<TEvent extends EventObject, TEmitted = any> ext
890
892
  toJSON?: () => any;
891
893
  }
892
894
  export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? SpawnedActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
895
+ /**
896
+ * @deprecated
897
+ */
893
898
  state: State<TContext, TEvent, any, TTypestate>;
894
899
  } : T extends Promise<infer U> ? SpawnedActorRef<never, U> : never;
895
900
  export declare type AnyInterpreter = Interpreter<any, any, any, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.19.2",
3
+ "version": "4.20.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",
@@ -66,7 +66,7 @@
66
66
  "rxjs": "^6.5.1",
67
67
  "ts-jest": "^26.5.6",
68
68
  "tslib": "^2.2.0",
69
- "typescript": "^4.2.4",
69
+ "typescript": "^4.3.2",
70
70
  "xml-js": "^1.6.11"
71
71
  }
72
72
  }