Fork me on GitHub
#re-frame
<
2017-01-21
>
tdavis15:01:46

Hey all, having trouble adapting a particular use case to re-frame, maybe you can help. I wrote an interceptor for :active-panel changes that checks if the user is authenticated. if they aren't, i force navigate! (via accountant) to the login page. So far so good. Then I added the ability to add alerts to the DB so i could let them know, hey, you gotta login before going to that page. However, I cannot figure out how to clear the alerts before/after a given panel change (so they don't just stack up in the UI forever) without making them disappear from the active panel, since I subscribe to that key in the DB.

tdavis15:01:48

I did briefly use :dispatch-later to give the user 30 seconds or so to read the alert before removing it, but that is sub-optimal and its sudden removal from the DOM shifted things around too much for my taste. The best analogy I can come up with is when you do a traditional server-side POST, there's some issue, you render the template again with the errors visible, but they don't carry over to other pages or even when hitting refresh on that page.

emccue16:01:35

Maybe you could go with the timed concept and just animate it off screen

emccue16:01:46

Then when it is off you remove it from your dom

emccue16:01:21

(with my mental picture being a red bar at the bottom of the screen floating above the rest of the content

emccue16:01:22

Or better yet, that alert sends a signal to remove itself from db

tdavis17:01:46

Yeah, I suppose at that point I might as well just use something like toastr and have it live entirely separate rather than implement the fading and timing stuff myself

witek19:01:09

Hi. Is it a good idea to use (dereference) subscriptions inside event handlers? I would like to do this to avoid duplication computations for values which already have been computed (and cached) in the subscription. Or am I totally wrong here?

witek19:01:53

For example I have a computation intensive subscription :favorite-items. I also have an event :do-something-with-favorite-items. Do I have to recompute the list of favorite items from db in the event handler again? Or can I use the subscription inside my event handler and ignore the provided db?

practicalli-johnny20:01:40

@mikethompson: thanks for the advice, we found a great reagent tutorial on lambdaisland, building a simple Kanban board. We will do some background reading on re-frame and work on that next