-
Notifications
You must be signed in to change notification settings - Fork 18
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
Passing context to computations when calling run() #1
Comments
It'd be useful not just for testing. I want to run some computation multiple times with different parameters. How should I do that? |
Yeah, this is certainly not only for testing, testing is just an example. Actually the use case I had in mind is React server rendering. We may have different API for data fetching, cookies, etc. on the server and in the browser, but still write unified code using tasks, which we then The alternative to context, and what is usually done with promises etc. is to use closures: function createSomeTask(context) {
return Task.create(...).chain(...).map(...)...
}
// on server
createSomeTask(serverContext).run(...)
// in browser
createSomeTask(browserContext).run(...)
So the |
Thanks, wrapping in a closure seems sufficient, IMO. |
Not sure whether this is a good idea or not, but it might be...
The idea is to make this possible:
This might be useful for testing for example. We could pass an API for data fetching as context, and during testing we could use a mocked fetching API.
The text was updated successfully, but these errors were encountered: