Fork me on GitHub
#re-frame
<
2018-12-17
>
Whiskas12:12:58

It works like a charm, you kinda just need to make sure the server will return index.html for everything that is’nt a resource/file on the server

Whiskas12:12:26

or you make the server to return index specifically for the pages of your spa

Whiskas14:12:46

how do you guys set intervals on re-frame?

Whiskas14:12:56

like, something to periodically dispatch an event for example

danielstockton14:12:26

js/setInterval on did-mount, and teardown on will-unmount?

danielstockton14:12:46

This is how i usually do it, not re-frame specific.

Whiskas14:12:07

i am doing that, actually i should have asked if you guys use some standard effect for that

Whiskas14:12:25

i was wondering about if it was correct to dispatch events from effects

Whiskas14:12:35

but i found an example showing that this is ok

danielneal14:12:36

I do this:

(reg-event-fx
  :timer/start
  (fn [cofx [_ opts]]
    (let [{:keys [db]} cofx
          {:keys [interval-ms on-tick id]} opts]
      {:db (assoc-in db [:timers id] (assoc opts :status :started))
       :dispatch-later [{:ms interval-ms :dispatch [:timer/tick id]}]})))

(reg-event-fx
  :timer/tick
  (fn [cofx [_ id]]
    (let [{:keys [db]} cofx
          {:keys [interval-ms on-tick id status]} (get-in db [:timers id])]
      (when (= status :started)
        {:dispatch on-tick
         :dispatch-later [{:ms interval-ms :dispatch [:timer/tick id]}]}))))

(reg-event-db
  :timer/stop
  (fn [db [_ id]]
    (update-in db [:timers id] assoc :status :stopped)))

danielneal14:12:20

Probably not as good as setInterval though

bobcalco15:12:25

@mateus.pimentel.w I'm using Pedestal on the back end and could use some guidance for the following goal: I want "/" to go to a static landing page with a different CSS style altogether than the portal at "/admin" that the user logs into through "/admin/login". Since re-frame apps mount a div by ID, I don't seem to have the control I want over the HTML document as a whole. When I slurp a different index.html for admin at "/admin" in my Pedestal routes configuration, Bidi always gives me the "page not found" view (see re-frame-starter at github). even though I defined the route as ["\" {"admin" :homepage ...}]. Anything under that, goes through Pedestal's routing. bidi can't seem to handle not being off "/" as the starting point for the SPA, or I just don't know how to make it work right with Pedestal for my specific needs. In any case, if I can find some way instead to support multiple page designs, I would be happy with one SPA for the front and back ends, and Bidi would probably work with that. Can re-frame/reagent take over the whole document, or must I always mount a named div?

mbertheau16:12:19

Where can I rent a re-frame expert for an hour or two? Berlin would be nice, but anywhere really is fine.

Whiskas16:12:17

@bob592 you need pushy to do what you want

Whiskas16:12:46

pushy + bidi

bobcalco17:12:49

@mateus.pimentel.w OK i'll look into that.

Whiskas17:12:34

@bob592 that article i sent you is like an walkthrough, i think you will have success following it

Braden Shepherdson20:12:15

I want to make a layer-3 subscription with two inputs, but that only updates when one of those inputs is changed.

Braden Shepherdson20:12:41

I suppose there's some way to make that work properly with reg-sub-raw.

b2berry20:12:24

What’s a nice way to prevent the app-db being completely reset when a user refreshes the page?

Braden Shepherdson20:12:24

you can fairly seamlessly persist all or parts of the app-db to and from localstorage, for example.

b2berry21:12:09

Yeah that’s the first place my head went to, too.

lilactown23:12:58

@mikethompson have you dug into how re-frame’s dispatch queue fits in with React’s new async rendering / “Concurrent Mode”?

lilactown23:12:43

is it even necessary? it sounds like React basically does prioritization of each event now