Replies: 4 comments
-
Hey, the general way we would model this is with several events. So one way you could do this is:
Hope that helps? You might also want to look at https://github.com/Day8/re-frame-async-flow-fx. Both that library and this one are mostly higher level patterns on top of re-frame primitives. I'd probably recommend starting off trying the pattern I suggested above. If that gets too unwieldy or you end up with too much duplicated code then you could look at those libraries to clean up some of the code. You might also get different opinions from others on the #re-frame Clojure Slack channel, the ClojureScript mailing list, or the Reagent mailing list. |
Beta Was this translation helpful? Give feedback.
-
@danielcompton Hi daniel, thanks for the response! (I have tried clojure slack but didn't have success there with this particular issue :) So I think the one missing part is where I mentioned that [:load-acls] may or may not need to do this effect after the fact. Does passing a custom callback handler like [:load-acls :success-callback #(foo)] seem like a reasonable pattern? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I don't quite understand. Can you explain further?
I would try to do as little work and decision making outside of handlers. You can look at sending your HTTP request as an event, and modelling the response as another event. Your event comes back and in the response handler you decide what to do about it (maybe nothing). |
Beta Was this translation helpful? Give feedback.
-
@danielcompton It's not the case that every time I run [:load-acls] I want this event to execute, is what I mean there. Some pages may just want to load acls and not consider redirection at all. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I've had trouble finding a way to do the following, and it looks like the coeffects strategy in this package might be along the right lines, so hoping someone will take a look at this and give me some advice.
Say I hit a new page (in the SPA) that has some ACLs, so only certain users can see the page.
I dispatch some
[:load-acls user]
.After the acls come back, if the user doesn't have said permissions, I want to redirect the user away.
This is the thing I've had trouble finding the appropriate pattern for (as well as other similar cases where there's a data dependency). But there may be times I want to load those same ACLs and then not redirect a user.
Would it be sane to pass a coeffect to the load-acls, e.g.
That's not quite the whole store, as a data load may be asynchronous, but that's roughly my thought at the moment.
Is that sort of where I want this in the stack? Would there be a better place? Potentially-dispatching in the pure render function seems like a big no-no, but it's currently the only place I actually have view-specific code outside of callbacks.
I've mostly had to rely on callbacks for this sort of behavior, which seems suboptimal. (that is, :load-acls has an optional callback for after data is loaded)
What's an appropriate/good/clean pattern to do these sorts of dependent-asynchronous-loads?
Beta Was this translation helpful? Give feedback.
All reactions