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

Why not re-frame effect handler? #21

Closed
olimsaidov opened this issue Mar 28, 2018 · 4 comments
Closed

Why not re-frame effect handler? #21

olimsaidov opened this issue Mar 28, 2018 · 4 comments

Comments

@olimsaidov
Copy link

Is there any reason behind why this lib does not integrate itself to re-frame as an effect handler?

@oliyh
Copy link
Owner

oliyh commented Mar 28, 2018

No real reason, it would be quite trivial to add though

@oliyh
Copy link
Owner

oliyh commented Mar 30, 2018

Although @olimsaidov you can always have a dispatch event which would look almost identical, i.e. effects of:

{:dispatch [::re-graph/query ...]}

vs

{::re-graph/query [...]}

Could you explain to me the benefits of the second (or drawbacks of the first)?

Thanks

@olimsaidov
Copy link
Author

I am fairly new to clojurescript, but, after reading re-frame docs I learned that all side-effects must be handled via effect handlers. Also there are many third-party libraries for re-frame which use effect handlers for making side-effects: https://github.com/olieidel/awesome-re-frame#effect-handlers

@oliyh
Copy link
Owner

oliyh commented Mar 31, 2018

re-graph does do all its side-effecty things (creating websockets, sending messages) via fx handlers. In fact, a dispatch is an effect itself, just one that happens to be built into re-frame. So, the two snippets I wrote above are functionally equal.

If I were to write fx handlers for the re-graph API they would look like this:

(re-frame/reg-fx
  ::query
  (fn [& args]
    (re-frame/dispatch (into [::query] args))))

So you see the fx handler would just be an extra step to achieve the same thing. With a dispatch it does the same thing, however, you have added flexibility to dispatch-n or dispatch-later as well.

@oliyh oliyh closed this as completed Aug 31, 2018
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