Skip to content

Commit 4b46233

Browse files
committed
Merge branch 'master' of github.com:2Toad/fluent-state
2 parents 30bd8d2 + a398154 commit 4b46233

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ A fluent JavaScript State Machine (with TypeScript support)
1010

1111
Install package
1212

13-
```
13+
```Shell
1414
npm i @2toad/fluent-state
1515
```
1616

1717
## Usage
1818

19-
```
19+
```JavaScript
2020
import { fluentState } from '@2toad/fluent-state';
2121
// or
2222
var fluentState = require('@2toad/fluent-state').fluentState;
@@ -45,15 +45,15 @@ The current state
4545
#### from(name: string): State
4646
Adds a state
4747

48-
```
48+
```JavaScript
4949
// Add the 'vegetable' state
5050
fluentState.from('vegetable');
5151
```
5252

5353
#### to(name: string): Transition
5454
Adds a transition to a state
5555

56-
```
56+
```JavaScript
5757
fluentState
5858
.from('vegetable') // Add the 'vegetable' state
5959
.to('diced'); // add the 'diced' state, with a transtion from 'vegetable'
@@ -62,7 +62,7 @@ fluentState
6262
#### or(name: string): Transition
6363
Adds a transition to a state
6464

65-
```
65+
```JavaScript
6666
fluentState
6767
.from('vegetable') // Add the 'vegetable' state
6868
.to('diced') // add the 'diced' state, with a transtion from 'vegetable'
@@ -73,7 +73,7 @@ fluentState
7373
#### setState(name: string): void
7474
Explicitly set the state without triggering a transition
7575

76-
```
76+
```JavaScript
7777
fluentState.setState('diced');
7878
```
7979

@@ -82,21 +82,21 @@ fluentState.setState('diced');
8282
#### has(name: string): boolean {
8383
Returns true if the state exists
8484

85-
```
85+
```JavaScript
8686
fluentState.has('vegetable');
8787
```
8888

8989
### remove(name: string): void
9090
Removes a state (and all of its transitions)
9191

92-
```
92+
```JavaScript
9393
fluentState.remove('vegetable');
9494
```
9595

9696
#### clear(): void
9797
Removes all states
9898

99-
```
99+
```JavaScript
100100
fluentState.clear();
101101
```
102102

@@ -105,7 +105,7 @@ fluentState.clear();
105105
- If multiple states are specified, a state is chosen at random.
106106
- Returns `true` upon success.
107107

108-
```
108+
```JavaScript
109109
// Transition to the 'diced' state
110110
fluentState.transition('diced');
111111

@@ -119,7 +119,7 @@ fluentState.transition('diced', 'discarded');
119119
- With the option to exclude specified states from the random selection.
120120
- Returns `true` upon success.
121121

122-
```
122+
```JavaScript
123123
fluentState.next();
124124

125125
// A random state, excluding 'pickled' and 'discarded'
@@ -132,14 +132,14 @@ You can add callbacks to any state
132132
#### when(name: string): Event
133133
Specifies the state you want to add a callback to
134134

135-
```
135+
```JavaScript
136136
fluentState.when('diced');
137137
```
138138

139139
#### do(handler: (previousState: State, fluentState: FluentState) => any): Handler
140140
Adds a callback
141141

142-
```
142+
```JavaScript
143143
fluentState
144144
.when('diced')
145145
.do((previousState, fluentState) => {
@@ -150,7 +150,7 @@ fluentState
150150
#### and(handler: (previousState: State, fluentState: FluentState) => any): Handler
151151
Adds another callback
152152

153-
```
153+
```JavaScript
154154
fluentState
155155
.when('diced')
156156
.do(() => console.log('Transitioned to "diced"'))
@@ -161,7 +161,7 @@ fluentState
161161

162162
> And of course it's all chainable
163163
164-
```
164+
```JavaScript
165165
fluentState
166166
.when('diced').do(() => console.log('Transitioned to "diced"'))
167167
.when('pickled').do(() => console.log('Transitioned to "pickled"'));
@@ -170,7 +170,7 @@ fluentState
170170
### Lifecycle
171171
You can hook into the state machine lifecycle via the `observe` method.
172172

173-
```
173+
```JavaScript
174174
fluentState.observe(Lifecycle.BeforeTransition, (currentState, newState) => {
175175
// You can prevent the transition by returning false from this event
176176
return false;

0 commit comments

Comments
 (0)