Skip to content
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

Open
rpominov opened this issue Jul 23, 2016 · 3 comments
Open

Passing context to computations when calling run() #1

rpominov opened this issue Jul 23, 2016 · 3 comments

Comments

@rpominov
Copy link
Owner

rpominov commented Jul 23, 2016

Not sure whether this is a good idea or not, but it might be...

The idea is to make this possible:

const task = Task.create((onSucc, onFail, context) => {
  // context === 123
  // ...
}).chain(x => Task.create((onSucc, onFail, context) => {
  // context === 123
  // ...
})
task.run(onSucc, onFail, 123)

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.

@rvikmanis
Copy link

rvikmanis commented Jul 27, 2016

It'd be useful not just for testing.

I want to run some computation multiple times with different parameters. How should I do that?

@rpominov
Copy link
Owner Author

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 run() with different contexts.

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(...)

I want to run some computation multiple times with different parameters. How should I do that?

So the context feature should let you do that (though still not sure whether it's good idea) or you can just create two tasks.

@rvikmanis
Copy link

Thanks, wrapping in a closure seems sufficient, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants