Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Replaying events with side effects in handlers? #86

Closed
vladar opened this issue Jul 22, 2015 · 5 comments
Closed

Replaying events with side effects in handlers? #86

vladar opened this issue Jul 22, 2015 · 5 comments
Labels

Comments

@vladar
Copy link

vladar commented Jul 22, 2015

I have just started playing with re-frame. And I wonder: how do you replay events if your event handlers have side effects (like HTTP requests following new dispatches)?

Or maybe I am missing something?

@danielcompton
Copy link
Contributor

This looks more like a question than a feature/bug report. I'm closing this here, but feel free to discuss it further on a better channel for discussion, e.g. Clojurians Slack, ClojureScript mailing list, Reagent mailing list. Thanks!

@metasoarous
Copy link

Did this lead to any interesting discussion somewhere? I don't find much documentation on best practices for handling side effects.

@danielcompton
Copy link
Contributor

As a general principle, side effects should always be initiated in handlers. Where there is a remote call, we have two (or three) handlers. The handler that makes the request, the handler that gets called on success, and the hanswer that gets called on error.

@juhovh
Copy link

juhovh commented Jun 12, 2016

I have been wondering about this as well, it's not a very nice practice that some handlers cause side effects and some don't.

Let's consider a case where I have a user using my re-frame enabled application. Sometimes there are some issues and I want to be able to log all actions that the user has made and replay them locally without any side effects (the results of side effects are still in separate actions, which I do want to replay). Now if I do not know which actions cause side effects, it is impossible to filter those out. But unless I filter them out my local instance might start to make calls to the backend with that user's session and access my browser's local storage or cookies, which in turn might make reproducing the bug impossible.

I don't think this is just a theoretical discussion, but a serious concern for anyone trying to store a side effect free stream of events. I've been thinking about this for a while, and I think what I probably would want is a register-effect function that would allow me to register side effect middlewares similar to how redux-effects works. It would be a single event handler with a (possibly namespaced) keyword as its key, and the actual side effect causing event as its payload. Then if I want to replay events, I would simply replace this event-handler with a no-op (that only dispatches the original event without its side effects) and everything would work as expected.

I haven't written a proof-of-concept yet, so not completely sure if this is the sensible way to go. I also recommend reading the related blog post, even though I think the suggested solution there results in a bit unreadable code, and I wouldn't want to go with that.

@danielcompton
Copy link
Contributor

These are all great points, can you bring them up on the Reagent mailing list to discuss them further?

@day8 day8 locked and limited conversation to collaborators Mar 29, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants