-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
composable / higher order effects #34
Comments
another example is how to implement sagas in from my understanding, for effects to work as sagas, you must be able to subscribe to all future actions and dispatch any number of actions at any time. |
dammit, |
I've been giving this a lot of thought and I think that what's needed is a callback in const http = require('choo/http')
app.model({
effects: {
makeXhrRequest: (state, action, send, cb) => {
http.get('/foo/bar', function (err, res, body) {
if (err) return cb(err)
cb()
})
},
foobar: (state, action, send, cb) => {
send('makeXhrRequest', function (err, res) {
if (err) {
console.log('all is bad D:')
cb()
} else {
send('makeXhrRequest', function (err, res) {
if (err) {
console.log('all is bad D:')
cb()
} else {
console.log('all is good :D')
cb()
}
})
}
})
}
}
}) Obv in a real world scenario we'd use proper async abstractions such as map-limit or pull-stream, but I hope the point comes across. Does this make sense? |
Should prob make the callback optional by doing a |
A very similar pattern has arisen from my redux action code. Careful with calling them sagas though since people have a very specific coupling of syntax i.e. generators etc. with that name. |
ah yeah you're right, at this point I reckon calling it "composable effects" or "higher order effects" is probabably better - nice one! If we're going to build choo / yo-yo guide we should probably put a migration guide for react in there hah |
👍 on having a migration guide. |
@yoshuawuyts Could you write up an example of using |
@bitwiselove I'd love to, but I'm slightly swamped in getting v3 out first (choo's suddenly gotten popular haha) - perhaps take a look at I'm sure we'll get more of this out there post v3 - just trying to get through this initial spike of popularity and breaking changes unscathed rn haha |
hey @bitwiselove, do you have a specific real-world use case in mind? feel free to make an issue on |
Closing as 3.0 is imminent; wanna make sure all issues are taken care of. Releasing soooon™ ✨ |
Sometimes multiple actions need to be chained to make a thing happen. For example: logging a user out means that:
redux
has a concept ofredux-saga
to handle this. It's basically a way of combining multiple actions into a higher-order flow. Pretty damn interesting, and definitely useful. Actually I built exactly this stuff last year in the form of barracks.So umm, I think probably the right way of dealing with this is to allow for callbacks from within
effects
so they can be composed into higher ordereffects
(which we can then refer to assagas
, although they'd simply be a pattern).An example:
I feel like
send()
loses a bit of its semantic meaning here, perhaps an extra, optionalcb()
argument should be added? Anyway, I hope the idea comes across. I feel like the idea is there, but I'm overlooking quirks and the consumer-facing API isn't quite where it could be - suggestions are heaps welcome! - Cheers ✨See Also
The text was updated successfully, but these errors were encountered: