-
Notifications
You must be signed in to change notification settings - Fork 22
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
Wrap handlers #59
Wrap handlers #59
Conversation
I am very excited about this. I already created an An example I have is: export function wrapEffect (cb) {
return async (data, state, send, done) => {
const newSend = (action, data = null) => {
return new Promise((resolve, reject) => {
send(name, data, (err, res) => {
if (err) {
done(err) // communicate error to choo
reject(err) // throw
} else {
resolve(res) // move forward
}
})
})
}
await cb(data, state, newSend)
done() // auto-done when everything is done
}
} which allowed me to write this in the end: app.model({
effects: {
reloadMailsCount: wrapEffect(async (data, state, send) => {
const count = await storage.getMailsCount()
await send('receiveMailsCount', count)
})
}
}) Is this the type of thing you are hoping to enable? |
@myobie Hah yeah, pretty much! I'm a strong opponent of Promises myself, but I want people that like them to be able to use them as they please (as with other paradigms). A little note: for your implementation to be correct you'd probably have to wrap it in a |
@yoshuawuyts great idea, I will do that. And yes, promises + try/catch do sometimes make my head hurt. I'm not entirely sure what |
@myobie so when calling |
055cea7
to
27a66ad
Compare
Adds support for yoshuawuyts/barracks#59
Adds the functionality described in choojs/choo#145. Builds on #58. Pretttttty excited about this ✨