3 ms·
My example actually has no issues, but [here is an example][1] so you can confirm that. I included the implementation of `delay` there as well so you can also s
by jorgebucaran 6y ago
My example actually has no issues, but [here is an example][1] so you can confirm that. I included the implementation of `delay` there as well so you can also see what happens behind the scenes.
---
So, in Hyperapp there are no async/await functions. Or Promises. Can't use functions that create side effects. Can't use setTimeout, setInterval, new Promise, fetch, add/removeEventListener, etc.
delay(100, Action) looks familiar to setTimeout, but it's just a function that returns an object that tells Hyperapp what to do. It doesn't do anything by itself. You can write your own delay function too if you want as long as you give Hyperapp what it wants.
The state becoming stale is never an issue in Hyperapp, because you get a fresh copy of it inside actions, which is the only place where you can "update" the state.
[1]: https://codesandbox.io/s/hyperapp-minimal-counter-with-effect-for-hn-old-dude-evvm4?file=/src/index.js https://codesandbox.io/s/hyperapp-minimal-counter-with-effec...
- _old_dude_ 6y agoThanks for taking the time to explain me how it works. So you're right that you can not use a previous state. And if i want to get the dispatcher directly, i can write a helper function function effect(fun) { return state => [state, [dispatcher => fun(dispatcher)]] } and use it to access to the dispatcher/updater h( "button", { onclick: effect(updater => setTimeout(() => updater(Decrement), 1000)) }, "subtract" ) Thanks a lot !
- jorgebucaran 6y agoBasically, yes! In practice, we don't advocate users to reach out for dispatch, as Hyperapp intends to provide all the fx/subscriptions building blocks you need to create the right abstractions and stay within the safe, declarative side of things. The reality is, though, that crafting these building blocks takes time and thought, so we don't have them all yet. But people in the community have created fx/sub libraries that are already available, see e.g. this one: https://github.com/okwolf/hyperapp-fx https://github.com/okwolf/hyperapp-fx that Cheers!