Skip to content

Commit

Permalink
Remove createModel (#3187)
Browse files Browse the repository at this point in the history
* Remove createModel

* Add changeset
  • Loading branch information
davidkpiano committed Jun 8, 2022
1 parent a990f0e commit c800dec
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 1,116 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-rocks-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': major
---

The `createModel()` function has been removed in favor of relying on strong types in the machine configuration.
4 changes: 2 additions & 2 deletions docs/guides/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const machine = createMachine({
},
initial: 'a',
context: {
value: '',
value: ''
},
states: {
a: {
Expand Down Expand Up @@ -78,7 +78,7 @@ const machine = createMachine({
events: {} as { type: 'FOO'; value: string } | { type: 'BAR' }
},
context: {
value: '',
value: ''
},
initial: 'a',
states: {
Expand Down
46 changes: 23 additions & 23 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
And creating your own custom dev tools adapter is a function that takes in the `service`:

```js
const myCustomDevTools = service => {
const myCustomDevTools = (service) => {
console.log('Got a service!');

service.subscribe(state => {
service.subscribe((state) => {
// ...
});
};
Expand Down Expand Up @@ -308,7 +308,7 @@
let previousState;

const service = interpret(someMachine)
.onTransition(state => {
.onTransition((state) => {
// previousState represents the last state here

// ...
Expand Down Expand Up @@ -507,7 +507,7 @@
// This will
const loggedInState = await waitFor(
loginService,
state => state.hasTag('loggedIn'),
(state) => state.hasTag('loggedIn'),
{ timeout: Infinity }
);
```
Expand Down Expand Up @@ -540,7 +540,7 @@
// ...
const loginService = interpret(loginMachine).start();

const loggedInState = await waitFor(loginService, state =>
const loggedInState = await waitFor(loginService, (state) =>
state.hasTag('loggedIn')
);

Expand Down Expand Up @@ -677,7 +677,7 @@

```js
// Persisting a state
someService.subscribe(state => {
someService.subscribe((state) => {
localStorage.setItem('some-state', JSON.stringify(state));
});

Expand Down Expand Up @@ -933,10 +933,10 @@

model.createMachine({
// `ctx` was of type `any`
entry: ctx => {},
entry: (ctx) => {},
exit: assign({
// `ctx` was of type `unknown`
foo: ctx => 42
foo: (ctx) => 42
})
});
```
Expand Down Expand Up @@ -1112,11 +1112,11 @@
const machine = createMachine({
context: { count: 0 },
entry: [
ctx => console.log(ctx.count), // 0
assign({ count: ctx => ctx.count + 1 }),
ctx => console.log(ctx.count), // 1
assign({ count: ctx => ctx.count + 1 }),
ctx => console.log(ctx.count) // 2
(ctx) => console.log(ctx.count), // 0
assign({ count: (ctx) => ctx.count + 1 }),
(ctx) => console.log(ctx.count), // 1
assign({ count: (ctx) => ctx.count + 1 }),
(ctx) => console.log(ctx.count) // 2
],
preserveActionOrder: true
});
Expand All @@ -1125,11 +1125,11 @@
const machine = createMachine({
context: { count: 0 },
entry: [
ctx => console.log(ctx.count), // 2
assign({ count: ctx => ctx.count + 1 }),
ctx => console.log(ctx.count), // 2
assign({ count: ctx => ctx.count + 1 }),
ctx => console.log(ctx.count) // 2
(ctx) => console.log(ctx.count), // 2
assign({ count: (ctx) => ctx.count + 1 }),
(ctx) => console.log(ctx.count), // 2
assign({ count: (ctx) => ctx.count + 1 }),
(ctx) => console.log(ctx.count) // 2
]
// preserveActionOrder: false
});
Expand Down Expand Up @@ -1328,7 +1328,7 @@
});

const service = interpret(machine)
.onTransition(state => {
.onTransition((state) => {
// Read promise value synchronously
const resolvedValue = state.context.promiseRef?.getSnapshot();
// => undefined (if promise not resolved yet)
Expand Down Expand Up @@ -1408,7 +1408,7 @@
context: { value: 42 },
on: {
INC: {
actions: assign({ value: ctx => ctx.value + 1 })
actions: assign({ value: (ctx) => ctx.value + 1 })
}
}
});
Expand Down Expand Up @@ -1668,7 +1668,7 @@
```js
// ...
actions: stop(context => context.someActor);
actions: stop((context) => context.someActor);
```
### Patch Changes
Expand Down Expand Up @@ -1906,10 +1906,10 @@
```js
entry: [
choose([
{ cond: ctx => ctx > 100, actions: raise('TOGGLE') },
{ cond: (ctx) => ctx > 100, actions: raise('TOGGLE') },
{
cond: 'hasMagicBottle',
actions: [assign(ctx => ({ counter: ctx.counter + 1 }))]
actions: [assign((ctx) => ({ counter: ctx.counter + 1 }))]
},
{ actions: ['fallbackAction'] }
])
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"./index.ts",
"./actions.ts",
"./actors.ts",
"./model.ts",
"./guards.ts",
"./dev/index.ts"
]
Expand Down
81 changes: 0 additions & 81 deletions packages/core/src/model.ts

This file was deleted.

144 changes: 0 additions & 144 deletions packages/core/src/model.types.ts

This file was deleted.

Loading

0 comments on commit c800dec

Please sign in to comment.