Ok, so after debugging the sandbox a bit I think I get it...
The cleanup function (that turns canceled into true) only runs when state changes from loading to something else (because it is only returned in the loading state).
So... if we've changed from loading to idle before the promise has returned, when it returns the canceled flag will be true and it will return without doing anything.
I do however feel that this logic kind of goes against what this entire post is trying to advocate: declarative, easy to understand logic.
I'm wondering if maybe there's a more "state machiney" way to implement this functionality (without going full on state machine like in the last example)
I also stumbled over this example and agree that explicit cancelation would make the app logic easier to understand. Implicit cancelation feels too close to the isLoading from the very first example.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ok, so after debugging the sandbox a bit I think I get it...
The cleanup function (that turns
canceled
intotrue
) only runs when state changes fromloading
to something else (because it is only returned in the loading state).So... if we've changed from
loading
toidle
before the promise has returned, when it returns the canceled flag will be true and it will return without doing anything.I do however feel that this logic kind of goes against what this entire post is trying to advocate: declarative, easy to understand logic.
I'm wondering if maybe there's a more "state machiney" way to implement this functionality (without going full on state machine like in the last example)
Yes there is, and Reason has done it - reasonml.github.io/reason-react/do...
I also stumbled over this example and agree that explicit cancelation would make the app logic easier to understand. Implicit cancelation feels too close to the
isLoading
 from the very first example.