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

Rule prefer-map-over-sample #66

Closed
igorkamyshev opened this issue Oct 22, 2021 · 2 comments
Closed

Rule prefer-map-over-sample #66

igorkamyshev opened this issue Oct 22, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@igorkamyshev
Copy link
Member

I found such code:

const sendEvent = sample({ clock: somethingDone, fn: (payload) => mapper(payload) })

In my opinion, it should be rewritten in this way:

const sendEvent = somethingDone.map((payload) => mapper(payload))
@igorkamyshev igorkamyshev added the enhancement New feature or request label Oct 22, 2021
@Kelin2025
Copy link
Member

I'm not sure if this restriction is good.
Honestly, if time machines existed, I'd probably go back and remove all dot methods from effector units, instead make only operators (like map(unit, data => ...))

  1. To make it more consistent (everything through operators rather than switching between two notations)
  2. To have more control over codebase in terms of parsing (e.g. babel can always check if map() is imported from effector, but you have no guarantee that store in store.map is actually store). As I remember, @zerobias pointed that out as well
    In the example above, sample might be verbose but you don't need to rewrite the whole thing when you need to add store (you just add source instead of rewriting it)

Speaking of this - I'd ban forward({ from, to }) operator, and forced sample({ clock, target }) instead. The only problem is that forward has different execution priority rather than sample

@igorkamyshev
Copy link
Member Author

Yeah, you are right. Could you please open issue about forward({ from, to }) -> sample({ clock, target })?

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

No branches or pull requests

2 participants