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

Bound Flow functions #1767

Closed
mjewell opened this issue Oct 9, 2018 · 4 comments
Closed

Bound Flow functions #1767

mjewell opened this issue Oct 9, 2018 · 4 comments

Comments

@mjewell
Copy link

mjewell commented Oct 9, 2018

What is the recommended approach for creating bound asynchronous actions?

The docs recommend using flow, but since generators cannot be used with arrow functions it isn't clear how to make sure they are bound correctly. Does it make sense for there to be a flow.bound?

It looks like it's possible to use action.bound on a flow function, but I'm not sure if that has downsides. Alternatively, you can create a separate action that is bound, and call that from the flow function, but that doesn't seem ideal either.

Here's a code sandbox showing the issue (and the action.bound fix): https://codesandbox.io/s/zw7kz7m0vl

@urugator
Copy link
Collaborator

Dunno if recommended, but why not simply:
boundFlow = flow(function*() {/**/}).bind(this);
or
boundFlow = flow(function*() {/**/}.bind(this));

flow.bound

Since flow is not usable as decorator (not sure why), the above would just become:
boundFlow = flow.bound(function*() {/**/}, this);
Which doesn't seem as much of an improvement to me, quite the opposite actually.

action.bound on a flow function, but I'm not sure if that has downsides.

Functionally I don't think so, but seems a bit redundant.

@mweststrate
Copy link
Member

See also #1769 , pushing bind inwards is better type-checkable. Will make sure we get @flow.bound once a decorator version of flow is available

@azyobuzin
Copy link

In v6, flow is a decorator. I think if flow.bound is added, it will be convenient as action.bound.

@urugator
Copy link
Collaborator

#2906

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

4 participants