Skip to content

Commit 144157c

Browse files
committed
Use .value in readme
1 parent 7c6eda4 commit 144157c

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

readme.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ function Switch() {
151151
}
152152

153153
const machine = start(Switch);
154-
machine.current; // "Off"
154+
machine.value.state; // "Off"
155155
machine.next("FLICK");
156-
machine.current; // "On"
156+
machine.value.state; // "On"
157157
machine.next("TOGGLE");
158-
machine.current; // "Off"
158+
machine.value.state; // "Off"
159159
```
160160

161161
### `enter(action: () => undefined | unknown | Promise<unknown>)`
@@ -184,11 +184,11 @@ function Switch() {
184184

185185
const machine = start(Switch);
186186
machine.next("FLICK");
187-
console.log(recordOn, machine.current); // 1, "ON"
187+
console.log(onCount, machine.value.state); // 1, "ON"
188188
machine.next("FLICK");
189-
console.log(recordOn, machine.current); // 1, "OFF"
189+
console.log(onCount, machine.value.state); // 1, "OFF"
190190
machine.next("FLICK");
191-
console.log(recordOn, machine.current); // 2, "ON"
191+
console.log(onCount, machine.value.state); // 2, "ON"
192192
```
193193

194194
### `exit(action: () => undefined | unknown | Promise<unknown>)`
@@ -216,11 +216,11 @@ function Session() {
216216
}
217217

218218
const machine = start(Switch);
219-
console.log(lastSessionEnded, machine.current); // null, "SignedOut"
219+
console.log(lastSessionEnded, machine.value.state); // null, "SignedOut"
220220
machine.next("AUTHENTICATE");
221-
console.log(lastSessionEnded, machine.current); // null, "SignedIn"
221+
console.log(lastSessionEnded, machine.value.state); // null, "SignedIn"
222222
machine.next("LOG_OFF");
223-
console.log(lastSessionEnded, machine.current); // (current time), "SignedOut"
223+
console.log(lastSessionEnded, machine.value.state); // (current time), "SignedOut"
224224
```
225225

226226
### `cond(predicate: () => boolean, target: GeneratorFunction)`
@@ -251,11 +251,11 @@ function ButtonClickListener(button: HTMLButtonElement) {
251251
const button = document.createElement('button');
252252
const machine = start(ButtonClickListener.bind(null, button));
253253

254-
machine.current; // "initial"
254+
machine.value; // { state: "initial", change: 0 }
255255
button.click();
256-
machine.current; // "clicked"
256+
machine.value; // { state: "clicked", change: 1 }
257257
button.click();
258-
machine.current; // "clicked"
258+
machine.value; // { state: "initial", change: 1 }
259259
```
260260

261261
## Examples
@@ -299,19 +299,19 @@ function Loader() {
299299
}
300300

301301
const loader = start(Loader);
302-
loader.current; // "idle"
302+
loader.value; // { state: "idle", change: 0 }
303303

304304
loader.next("FETCH");
305-
loader.current; // "loading"
305+
loader.value; // { state: "loading", change: 1, results: Promise }
306306

307-
loader.results.then((results) => {
307+
loader.value.results.then((results) => {
308308
console.log("Fetched", results.fetchData); // Use response of fetch()
309-
loader.current; // "success"
309+
loader.value.state; // "success"
310310
});
311311

312312
/* 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"
315315
```
316316

317317
### Passing parameters to a machine with closures
@@ -349,14 +349,14 @@ function SpecificLoader() {
349349

350350
// Start our specific loader machine
351351
const loader = start(SpecificLoader);
352-
loader.current; // "idle"
352+
loader.value; // { state: "idle", change: 0 }
353353

354354
loader.next("FETCH");
355-
loader.current; // "loading"
355+
loader.value; // { state: "loading", change: 1, results: Promise }
356356

357-
loader.results.then((results) => {
357+
loader.value.results.then((results) => {
358358
console.log("Fetched", results.fetchData); // Use response of fetch()
359-
loader.current; // "success"
359+
loader.value.state; // "success"
360360
});
361361
```
362362

@@ -380,9 +380,9 @@ function AbortListener(controller: AbortController) {
380380
const aborter = new AbortController();
381381
const machine = start(AbortListener.bind(null, aborter));
382382

383-
machine.current; // "initial"
383+
machine.value; // { state: "initial", change: 0 }
384384
aborter.abort();
385-
machine.current; // "aborted"
385+
machine.value; // { state: "aborted", change: 1 }
386386
```
387387

388388
----

0 commit comments

Comments
 (0)