File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,12 +20,17 @@ npm add yieldmachine
2020``` javascript
2121import { call , on , start } from " yieldmachine" ;
2222
23+ const exampleURL = new URL (" https://example.org/" );
24+ function fetchData () {
25+ return fetch (exampleURL .toString ());
26+ }
27+
2328function Loader ({ url }) {
2429 function * idle () {
2530 yield on (" FETCH" , loading);
2631 }
2732 function * loading () {
28- yield call (fetch, [ url . toString ()] );
33+ yield entry (fetchData );
2934 yield on (" SUCCESS" , success);
3035 yield on (" FAILURE" , failure);
3136 }
@@ -37,13 +42,13 @@ function Loader({ url }) {
3742 return idle;
3843}
3944
40- const loader = start (Loader, { url : new URL ( " https://example.org/ " ) } );
45+ const loader = start (Loader);
4146loader .value ; // "idle"
4247
4348loader .next (" FETCH" );
4449loader .value ; // "loading"
4550
46- loader .promisedValue .then (response => {
51+ loader .resolved .then (([ response ]) => {
4752 // Use response of fetch()
4853 loader .value ; // "success"
4954});
You can’t perform that action at this time.
0 commit comments