Fork me on GitHub
#re-frame
<
2017-12-14
>
chang04:12:51

@mikerod a similar repo to ethlance but less in size: https://github.com/madvas/emojillionaire

mikerod14:12:31

@mohamedhayibor @nberger these are both nice. It’s starting to look like there are lot of sources to look at for re-frame “in the wild” at this point

Bravi14:12:02

can I ‘reset’ the dispatch-later events somehow when application loads? Basically I’m using figwheel and everytime I make a change, the dispatch-later events keep stacking up instead of starting with a clean plate

danielneal14:12:30

@bravilogy not as far as I know - dispatch-later calls js/setTimeout https://github.com/Day8/re-frame/blob/cee6d27373233ed3633c886adb321d402b67afd7/src/re_frame/interop.cljs#L37-L38 and without the id, there's no way to clear the timer

danielneal14:12:09

This 'event bleed' also cropped up for me when testing, but got round it by stubbing dispatch later and @mikethompson also added a purge-event-queue! api to clear off the events that were in the queue

Keith14:12:29

Hello! I have an issue that I think might be caused by my ignorance, but I’m hoping to get some help. I’m using re-frame-undo to trigger an undo div to be shown when there are :undos?. I’m trying to replicate how Google Keep implements the undo feature by hiding the div after 5 seconds. The issue I’m running into is, if I set the display to none after 5 seconds, I can only get it to run once (and only if I use with-let).

Keith14:12:30

If I don’t use with-let, the reset! call seems to retrigger the view function, which in turn binds a new atom and triggers a new js/setTimeout

danielcompton20:12:55

@kharper it sounds like you're making a form-1 reagent component when you should be making a form-2

Keith20:12:01

@danielcompton I see what you’re saying about form-2. After making those changes, it seems to work the first time without with-let, but not subsequent times. I think my issue is that my outer function is @(subscribe [:undos?]), but I’m not sure how to get around that

Rachel Westmacott21:12:47

Hello! I’m new to re-frame, but I’m coming from reagent. I’m having issues with ‘liveness’ in development. The browser keeps loading old code, and I have to continually reevaluate forms/reload namespaces manually (or lein clean and restart the REPL!) which is a bit underwhelming given what I’m used to with fighwheel. I assume that I’ve done something silly, but being rather new to re-frame (and a bit overwhelmed by the docs) I’m not quite sure where to look for my error. I ran lein new re-frame astro to generate the project. Any help much appreciated.

jakemcc22:12:12

@peterwestmacott You should be able to still use figwheel.

Rachel Westmacott22:12:21

I think that I am

Rachel Westmacott22:12:42

but when I change my code, figwheel seems to be reloading old code

Rachel Westmacott22:12:08

I’m not sure if old versions of functions are getting cached somewhere. It seems that way.

danielcompton22:12:41

@kharper if you share your code we can take a look. It's a common issue

Keith14:12:50

(defn undo-container []
  (when @(subscribe [:undos?])
	(fn []
	  (with-let [active? (reagent/atom true)]
		(js/setTimeout #(reset! active? false) 5000)
		[:div.undo-container-parent.fixed-bottom
		 [:div.undo-container (if @active?
								{:class "undo-container-active"}
								{:class "undo-container-inactive"})
		  [:div.undo-desc "Removed command."]
		  [:div.undo-button.mdl-button {:on-click #(do (dispatch [:undo])
													   (reset! active? false))}
		   "UNDO"]
		  [:div.mdl-button {:on-click #(dispatch [:purge-undos])} (:deselect-single-image-white images/svgs)]]]))))

Keith14:12:39

Sorry it took so long, I didn’t see your message until late yesterday. After reflecting on this, I’m thinking that a more efficient way of handling this is to introduce a queue or some sort that holds undo events. Then have the undo-container subscribe to that queue and only be visible when the queue is not empty.

Keith14:12:49

As far as the code that I shared goes, the resetting on the active? atom seems to work the first time, but subsequent updates to the :undos? subscription result in the function running with whatever active? was previously set to (false). This behavior seems to happen even if using let rather than with-let

danielcompton17:12:32

This line will only be run once (when @(subscribe [:undos?])

Keith19:12:06

You’re right.

Keith19:12:53

I pulled from this post to create the solution: https://github.com/Day8/re-frame/issues/233

(defonce timeouts
  (atom {}))

(reg-fx :dispatch-debounce
  (fn [{:keys [key event delay]}]
	(js/clearTimeout (@timeouts key))
	(swap! timeouts assoc key
	  (js/setTimeout (fn []
					   (dispatch event)
					   (swap! timeouts dissoc key))
		delay))))

Keith19:12:10

Then using that effect handler:

(reg-event-fx
  :purge-undos
  trim-v
  (fn [{:keys [db]} _]
	(clear-undos!)))

(reg-event-fx
  :purge-undos-later
  trim-v
  (fn [cofx _]
	{:dispatch-debounce {:key     ::undo     ;; a unique key
						 :event   [:purge-undos]    ;; an event vector
						 :delay  5000}}))       ;; the future time at which to issue

Keith14:12:39

In case anyone else runs into this in the future, @ericnormand addresses the exact situation I was running into in an article he recently wrote which can be found here: https://purelyfunctional.tv/guide/timeout-effect-in-re-frame/?__s=pwubnm5zvszxjjs25bng

danielcompton22:12:17

@peterwestmacott are you using the latest Figwheel? There are some recent changes to improve caching

danielcompton22:12:05

Can you try doing a complete clean reload? In case theres still stuff around from before the migration

Rachel Westmacott22:12:03

ah, I am behind a version on figwheel, I’ll try bumping that…

Keith19:12:53

I pulled from this post to create the solution: https://github.com/Day8/re-frame/issues/233

(defonce timeouts
  (atom {}))

(reg-fx :dispatch-debounce
  (fn [{:keys [key event delay]}]
	(js/clearTimeout (@timeouts key))
	(swap! timeouts assoc key
	  (js/setTimeout (fn []
					   (dispatch event)
					   (swap! timeouts dissoc key))
		delay))))

Keith19:12:10

Then using that effect handler:

(reg-event-fx
  :purge-undos
  trim-v
  (fn [{:keys [db]} _]
	(clear-undos!)))

(reg-event-fx
  :purge-undos-later
  trim-v
  (fn [cofx _]
	{:dispatch-debounce {:key     ::undo     ;; a unique key
						 :event   [:purge-undos]    ;; an event vector
						 :delay  5000}}))       ;; the future time at which to issue

Keith14:12:39

In case anyone else runs into this in the future, @ericnormand addresses the exact situation I was running into in an article he recently wrote which can be found here: https://purelyfunctional.tv/guide/timeout-effect-in-re-frame/?__s=pwubnm5zvszxjjs25bng