Skip to content

Commit 613de78

Browse files
committed
Add comments to first example
1 parent 54b1130 commit 613de78

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

readme.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,27 @@ function fetchData() {
2727
return fetch(exampleURL);
2828
}
2929

30+
// Define a machine just using functions
3031
function Loader() {
32+
// Each state is a generator function
3133
function* idle() {
3234
yield on("FETCH", loading);
3335
}
36+
// This is the ‘loading’ state
3437
function* loading() {
3538
yield entry(fetchData);
3639
yield on("SUCCESS", success);
3740
yield on("FAILURE", failure);
3841
}
42+
// States can be final
3943
function* success() {}
44+
// Or they can define transitions to other states
4045
function* failure() {
46+
// When the RETRY event happens, we transition from ‘failure’ to ‘loading’
4147
yield on("RETRY", loading);
4248
}
4349

50+
// Return the initial state from your machine definition
4451
return idle;
4552
}
4653

@@ -104,10 +111,6 @@ loader.resolved.then(([response]) => {
104111
// Use response of fetch()
105112
loader.value; // "success"
106113
});
107-
108-
/* Or with await: */
109-
// const [response] = await loader.resolved;
110-
// loader.value; // "success"
111114
```
112115

113116
----

0 commit comments

Comments
 (0)