This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-14
Channels
- # adventofcode (62)
- # beginners (78)
- # boot (26)
- # boot-dev (9)
- # cider (73)
- # cljs-dev (33)
- # cljsrn (36)
- # clojure (159)
- # clojure-android (1)
- # clojure-austin (1)
- # clojure-greece (79)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-russia (11)
- # clojure-spec (33)
- # clojure-uk (26)
- # clojurescript (107)
- # core-async (22)
- # core-logic (12)
- # cursive (16)
- # datomic (13)
- # devcards (5)
- # duct (36)
- # emacs (4)
- # figwheel (3)
- # fulcro (107)
- # graphql (171)
- # hoplon (27)
- # instaparse (24)
- # jobs-discuss (34)
- # juxt (3)
- # lein-figwheel (1)
- # leiningen (8)
- # lumo (11)
- # off-topic (9)
- # onyx (79)
- # parinfer (1)
- # pedestal (75)
- # re-frame (27)
- # rum (1)
- # shadow-cljs (11)
- # spacemacs (20)
- # specter (17)
- # unrepl (96)
@mikerod a similar repo to ethlance but less in size: https://github.com/madvas/emojillionaire
@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
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
https://stackoverflow.com/questions/8860188/is-there-a-way-to-clear-all-time-outs very hacky solution though
@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
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
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
).
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
@kharper it sounds like you're making a form-1 reagent component when you should be making a form-2
@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
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.
@peterwestmacott You should be able to still use figwheel.
I think that I am
but when I change my code, figwheel seems to be reloading old code
I’m not sure if old versions of functions are getting cached somewhere. It seems that way.
@kharper if you share your code we can take a look. It's a common issue
(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)]]]))))
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.
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
This line will only be run once (when @(subscribe [:undos?])
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))))
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
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
@peterwestmacott are you using the latest Figwheel? There are some recent changes to improve caching
Can you try doing a complete clean reload? In case theres still stuff around from before the migration
ah, I am behind a version on figwheel, I’ll try bumping that…
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))))
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
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