xstate 4.24.1 → 4.25.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,51 @@
1
1
  # xstate
2
2
 
3
+ ## 4.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2657](https://github.com/statelyai/xstate/pull/2657) [`72155c1b7`](https://github.com/statelyai/xstate/commit/72155c1b7887b94f2d8f7cb73a1af17a591cc74c) Thanks [@mattpocock](https://github.com/mattpocock)! - Removed the ability to pass a model as a generic to `createMachine`, in favour of `model.createMachine`. This lets us cut an overload from the definition of `createMachine`, meaning errors become more targeted and less cryptic.
8
+
9
+ This means that this approach is no longer supported:
10
+
11
+ ```ts
12
+ const model = createModel({});
13
+
14
+ const machine = createMachine<typeof model>();
15
+ ```
16
+
17
+ If you're using this approach, you should use `model.createMachine` instead:
18
+
19
+ ```ts
20
+ const model = createModel({});
21
+
22
+ const machine = model.createMachine();
23
+ ```
24
+
25
+ ### Patch Changes
26
+
27
+ - [#2659](https://github.com/statelyai/xstate/pull/2659) [`7bfeb930d`](https://github.com/statelyai/xstate/commit/7bfeb930d65eb4443c300a2d28aeef3664fcafea) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a regression in the inline actions type inference in models without explicit action creators.
28
+
29
+ ```js
30
+ const model = createModel(
31
+ { foo: 100 },
32
+ {
33
+ events: {
34
+ BAR: () => ({})
35
+ }
36
+ }
37
+ );
38
+
39
+ model.createMachine({
40
+ // `ctx` was of type `any`
41
+ entry: ctx => {},
42
+ exit: assign({
43
+ // `ctx` was of type `unknown`
44
+ foo: ctx => 42
45
+ })
46
+ });
47
+ ```
48
+
3
49
  ## 4.24.1
4
50
 
5
51
  ### Patch Changes
package/es/Machine.d.ts CHANGED
@@ -1,18 +1,12 @@
1
- import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate, EventFrom, BaseActionObject } from './types';
2
- import { Model, ModelContextFrom, ModelActionsFrom } from './model.types';
1
+ import { Model } from './model.types';
2
+ import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
3
3
  /**
4
4
  * @deprecated Use `createMachine(...)` instead.
5
5
  */
6
6
  export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
7
7
  export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
8
- export declare function createMachine<TModel extends Model<any, any, any, any>, TContext = ModelContextFrom<TModel>, TEvent extends EventObject = EventFrom<TModel>, TTypestate extends Typestate<TContext> = {
9
- value: any;
10
- context: TContext;
11
- }, TAction extends BaseActionObject = ModelActionsFrom<TModel>>(config: MachineConfig<TContext, any, TEvent, TAction> & {
12
- context: TContext;
13
- }, options?: Partial<MachineOptions<TContext, TEvent, TAction>>): StateMachine<TContext, any, TEvent, TTypestate>;
14
8
  export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
15
9
  value: any;
16
10
  context: TContext;
17
- }>(config: TContext extends Model<any, any, any, any> ? never : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
11
+ }>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
18
12
  //# sourceMappingURL=Machine.d.ts.map
package/es/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { EventObject, BaseActionObject } from './types';
2
- import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
2
+ import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
3
3
  export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
- export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = 'events' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['events']> : never, TComputedAction = 'actions' extends keyof TModelCreators ? 'actions' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['actions']> : any : any>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
4
+ export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
5
  //# sourceMappingURL=model.d.ts.map
package/lib/Machine.d.ts CHANGED
@@ -1,18 +1,12 @@
1
- import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate, EventFrom, BaseActionObject } from './types';
2
- import { Model, ModelContextFrom, ModelActionsFrom } from './model.types';
1
+ import { Model } from './model.types';
2
+ import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
3
3
  /**
4
4
  * @deprecated Use `createMachine(...)` instead.
5
5
  */
6
6
  export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
7
7
  export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
8
- export declare function createMachine<TModel extends Model<any, any, any, any>, TContext = ModelContextFrom<TModel>, TEvent extends EventObject = EventFrom<TModel>, TTypestate extends Typestate<TContext> = {
9
- value: any;
10
- context: TContext;
11
- }, TAction extends BaseActionObject = ModelActionsFrom<TModel>>(config: MachineConfig<TContext, any, TEvent, TAction> & {
12
- context: TContext;
13
- }, options?: Partial<MachineOptions<TContext, TEvent, TAction>>): StateMachine<TContext, any, TEvent, TTypestate>;
14
8
  export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
15
9
  value: any;
16
10
  context: TContext;
17
- }>(config: TContext extends Model<any, any, any, any> ? never : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
11
+ }>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
18
12
  //# sourceMappingURL=Machine.d.ts.map
package/lib/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { EventObject, BaseActionObject } from './types';
2
- import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
2
+ import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
3
3
  export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
- export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = 'events' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['events']> : never, TComputedAction = 'actions' extends keyof TModelCreators ? 'actions' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['actions']> : any : any>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
4
+ export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
5
  //# sourceMappingURL=model.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.24.1",
3
+ "version": "4.25.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",