consul/ui/packages/consul-ui/app/components/state-machine
hashicorp-copywrite[bot] 5fb9df1640
[COMPLIANCE] License changes (#18443)
* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 09:12:13 -04:00
..
README.mdx
index.hbs [COMPLIANCE] License changes (#18443) 2023-08-11 09:12:13 -04:00
index.js [COMPLIANCE] License changes (#18443) 2023-08-11 09:12:13 -04:00

README.mdx

---
class: ember
---
# StateMachine

```hbs
<StateMachine
  @chart={{xstateStateChartObject}}
  as |fsm|>
</StateMachine>
```

`<StateMachine />` is a renderless component that eases rendering of different states
from within templates using XState State Machine and Statechart objects.

**Please note**: This component is currently a gradual replacement for
StateChart, which has a less ergonmic interface. Guard and Action component are
currently omitted due to a preference to use entries to define those instead of
components (which is WIP)

### Arguments

| Argument/Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `chart` | `object` |  | An xstate statechart/state machine object |
| `initial` | `String` | The initial value of the state chart itself | The initial state of the machine/chart (defaults to whatever is defined on the object itself) |

The component currently yields 1 contextual components:

- `<fsm.State />`: Used for rendering matching certain states ([also see State Component](../state/README.mdx))

and 2 further objects:

- `fsm.dispatch`: An action to dispatch an xstate event
- `fsm.state`: The state object itself for usage in the `state-matches` helper

### Example

```hbs
<StateMachine
  @chart={{xstateStateChartObject}}
  as |fsm|>
    <fsm.State @matches="idle">
      Currently Idle
    </fsm.State>
    <fsm.State @matches="loading">
      Currently Loading
    </fsm.State>
    <fsm.State @matches={{array 'loading' 'idle'}}>
      Idle and loading
      <button disabled={{state-matches fsm.state "loading"}} onclick={{action fsm.dispatch "START"}}>Load</button>
    </fsm.State>
</StateMachine>
```

### See

- [Component Source Code](./index.js)
- [Template Source Code](./index.hbs)

---