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

Allow return of effects using yield-effects rule? #81

Open
blordpluto opened this issue Nov 10, 2022 · 4 comments
Open

Allow return of effects using yield-effects rule? #81

blordpluto opened this issue Nov 10, 2022 · 4 comments

Comments

@blordpluto
Copy link

blordpluto commented Nov 10, 2022

Sometimes it's necessary and idiomatic to directly return the result of an effect. Using the yield-effects linter rule in this case motivates the usage of return yield effect() syntax which feels odd.

For generators in general, both yield and return expressions result in values being returned. Both are legit outputs. Sandwiching the extra yield inside there doesn't actually appear to be necessary. There's no reason to pause the generator before ending it. You can just end it. So return yield "works", but it seems strange for a linter to insist on. 🤔

This maybe doesn't come up for people because most generators probably primarily deal with yields. Note that return yield could have specialized uses in non-saga generators: https://stackoverflow.com/a/42309429

If I'm wrong about this I would be grateful for any clarification.

@pke
Copy link
Owner

pke commented Nov 11, 2022

So you would like the linter to also accept return effect()?

@blordpluto
Copy link
Author

Yes.

@pke
Copy link
Owner

pke commented Nov 11, 2022

What would that do in terms of generators? It would not yield, would it?

@blordpluto
Copy link
Author

Well, yield and return expressions both "return" values. One needs to distinguish between the keyword and the concept.

return yield is unnecessary in sagas because the yield returns the effect, but allows the generator to be restarted. But when we know that we're finishing the generator with return, there's no reason to restart. Why would we want to pause before finishing, when we could just finish? The inner yield is superfluous. It's like an extra wrapper.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*#description

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