DEV Community

Discussion on: No, disabling a button is not app logic.

Collapse
 
uriklar profile image
Uri Klar

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)

Collapse
 
davidkpiano profile image
David K. 🎹

Yes there is, and Reason has done it - reasonml.github.io/reason-react/do...

Collapse
 
sapegin profile image
Artem Sapegin

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.