@Fuunnx
Nothing here yet.
Nothing here yet.
No blogs yet.
A callback works better than Promises or async/await in cases you need to subscribe to multiple values or events over time (ex: a websocket channel or DOM events). There is a nice abstraction on top of callbacks that handle multiple events : Observables (xstream, rxjs). It provides a nice chained api to filter, transform, accumulate, delay and debounce events (and a lot more). I you want to learn more about why Observables are just "callbacks" I recommend reading this article https://medium.com/@benlesh/learning-observable-by-building-observable-d5da57405d87 that has been enlightening to me about the nature of this primitive.
Reactive programming is a vast concept. RxJS is just a part of it but I can say is totally worth learning ! As far as I can tell, it has transformed my way of thinking about programs (this and functional programming too). If you are ready to dive in, I recommend viewing the egghead courses https://egghead.io/technologies/rx, reading this wiki https://github.com/foxdonut/meiosis/wiki, fiddling with the rxjs examples, follow this great tutorial https://github.com/channikhabra/yarr and try CycleJS (not especially in this order)
It doesn't solve all the problems, but if you need a little side effect (as the console.log statement in your example) in a simple arrow function, you can use this syntax : (value) => (sideEffect1(), sideEffect2(), mutate(value)) In this case the last element is implicitly returned. Your example : values.map((index, value) => { console.log(value) return mutate(index,value) } can become values.map((index, value) => (console.log(value), mutate(index,value)) And removing the console.log is easy too values.map((index, value) => (mutate(index,value)) It's a matter of taste but I like this syntax for small blocks while chaining functions