diff --git a/README.md b/README.md index bf040af5..797bd22b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ yarn add ember-statechart-component To be able to use XState [`state.matches`](https://xstate.js.org/docs/guides/states.html#state-matches-parentstatevalue) method in our templates, -we will first need a [HelperManager](https://github.com/emberjs/rfcs/pull/625) for +we will first need `ember-source@4.5+` or a [HelperManager](https://github.com/emberjs/rfcs/pull/625) for handling vanilla functions. [ember-functions-as-helper-polyfill](https://github.com/NullVoxPopuli/ember-functions-as-helper-polyfill) provides one: @@ -135,6 +135,30 @@ Usage: ``` +### Glint + +Having type checking with these state machines requires a wrapper function. + +```ts +// app/components/my-component.ts +import { createMachine } from 'xstate'; +import { asComponent } from 'ember-statechart-component/glint'; + +export const machine = createMachine(/* ... */); + +export default asComponent(machine); +``` +or, if you want 0 runtime cost there is a more verbose, type-only option: +```ts +// app/components/my-component.ts +import { createMachine } from 'xstate'; +import type { MachineComponent } from 'ember-statechart-component/glint'; + +export const machine = createMachine(/* ... */); + +export default machine as unknown as MachineComponent; +``` + ### API #### `@config` @@ -144,7 +168,7 @@ This argument allows you to pass a MachineConfig for [actions](https://xstate.js Usage:
Toggle machine that needs a config - + ```js // app/components/toggle.js import { createMachine, assign } from 'xstate'; @@ -153,8 +177,8 @@ export default createMachine({ initial: 'inactive', states: { inactive: { on: { TOGGLE: 'active' } }, - active: { - on: { + active: { + on: { TOGGLE: { target: 'inactive', actions: ['toggleIsOn'] @@ -168,12 +192,12 @@ export default createMachine({
```hbs -