@@ -151,11 +151,11 @@ function Switch() {
151
151
}
152
152
153
153
const machine = start (Switch );
154
- machine .current ; // "Off"
154
+ machine .value . state ; // "Off"
155
155
machine .next (" FLICK" );
156
- machine .current ; // "On"
156
+ machine .value . state ; // "On"
157
157
machine .next (" TOGGLE" );
158
- machine .current ; // "Off"
158
+ machine .value . state ; // "Off"
159
159
```
160
160
161
161
### ` enter(action: () => undefined | unknown | Promise<unknown>) `
@@ -184,11 +184,11 @@ function Switch() {
184
184
185
185
const machine = start (Switch );
186
186
machine .next (" FLICK" );
187
- console .log (recordOn , machine .current ); // 1, "ON"
187
+ console .log (onCount , machine .value . state ); // 1, "ON"
188
188
machine .next (" FLICK" );
189
- console .log (recordOn , machine .current ); // 1, "OFF"
189
+ console .log (onCount , machine .value . state ); // 1, "OFF"
190
190
machine .next (" FLICK" );
191
- console .log (recordOn , machine .current ); // 2, "ON"
191
+ console .log (onCount , machine .value . state ); // 2, "ON"
192
192
```
193
193
194
194
### ` exit(action: () => undefined | unknown | Promise<unknown>) `
@@ -216,11 +216,11 @@ function Session() {
216
216
}
217
217
218
218
const machine = start (Switch );
219
- console .log (lastSessionEnded , machine .current ); // null, "SignedOut"
219
+ console .log (lastSessionEnded , machine .value . state ); // null, "SignedOut"
220
220
machine .next (" AUTHENTICATE" );
221
- console .log (lastSessionEnded , machine .current ); // null, "SignedIn"
221
+ console .log (lastSessionEnded , machine .value . state ); // null, "SignedIn"
222
222
machine .next (" LOG_OFF" );
223
- console .log (lastSessionEnded , machine .current ); // (current time), "SignedOut"
223
+ console .log (lastSessionEnded , machine .value . state ); // (current time), "SignedOut"
224
224
```
225
225
226
226
### ` cond(predicate: () => boolean, target: GeneratorFunction) `
@@ -251,11 +251,11 @@ function ButtonClickListener(button: HTMLButtonElement) {
251
251
const button = document .createElement (' button' );
252
252
const machine = start (ButtonClickListener .bind (null , button ));
253
253
254
- machine .current ; // "initial"
254
+ machine .value ; // { state: "initial", change: 0 }
255
255
button .click ();
256
- machine .current ; // "clicked"
256
+ machine .value ; // { state: "clicked", change: 1 }
257
257
button .click ();
258
- machine .current ; // "clicked"
258
+ machine .value ; // { state: "initial", change: 1 }
259
259
```
260
260
261
261
## Examples
@@ -299,19 +299,19 @@ function Loader() {
299
299
}
300
300
301
301
const loader = start (Loader);
302
- loader .current ; // "idle"
302
+ loader .value ; // { state: "idle", change: 0 }
303
303
304
304
loader .next (" FETCH" );
305
- loader .current ; // "loading"
305
+ loader .value ; // { state: "loading", change: 1, results: Promise }
306
306
307
- loader .results .then ((results ) => {
307
+ loader .value . results .then ((results ) => {
308
308
console .log (" Fetched" , results .fetchData ); // Use response of fetch()
309
- loader .current ; // "success"
309
+ loader .value . state ; // "success"
310
310
});
311
311
312
312
/* Or with await: */
313
- // const { fetchData } = await loader.results;
314
- // loader.current ; // "success"
313
+ // const { fetchData } = await loader.value. results;
314
+ // loader.value.state ; // "success"
315
315
```
316
316
317
317
### Passing parameters to a machine with closures
@@ -349,14 +349,14 @@ function SpecificLoader() {
349
349
350
350
// Start our specific loader machine
351
351
const loader = start (SpecificLoader);
352
- loader .current ; // "idle"
352
+ loader .value ; // { state: "idle", change: 0 }
353
353
354
354
loader .next (" FETCH" );
355
- loader .current ; // "loading"
355
+ loader .value ; // { state: "loading", change: 1, results: Promise }
356
356
357
- loader .results .then ((results ) => {
357
+ loader .value . results .then ((results ) => {
358
358
console .log (" Fetched" , results .fetchData ); // Use response of fetch()
359
- loader .current ; // "success"
359
+ loader .value . state ; // "success"
360
360
});
361
361
```
362
362
@@ -380,9 +380,9 @@ function AbortListener(controller: AbortController) {
380
380
const aborter = new AbortController ();
381
381
const machine = start (AbortListener .bind (null , aborter ));
382
382
383
- machine .current ; // "initial"
383
+ machine .value ; // { state: "initial", change: 0 }
384
384
aborter .abort ();
385
- machine .current ; // "aborted"
385
+ machine .value ; // { state: "aborted", change: 1 }
386
386
```
387
387
388
388
----
0 commit comments