Fork me on GitHub
#re-frame
<
2018-04-01
>
robert-stuttaford14:04:15

is there a support group for cljs veterans new to re-frame / reagent? 🙂 i feel like i’m on the first day of the job again, butting my head against React basics…

robert-stuttaford14:04:33

of course, now that i’ve said that, i figured it out

naomarik14:04:40

always happens to me 😉

soulflyer16:04:59

Got a problem getting the new event code tracing feature of re-frame-10x working. Got the dependancy [day8.re-frame/tracing "0.5.0"] in the dev profile in project.clj but compile fails when I add the :require to my namespace. Tried 2 variations that appear in the install instructions, [day8.re-frame.tracing :refer-macros [fn-traced]] and [day8.re-frame.tracing :refer [fn-traced defn-traced]] Both give the same message via figwheel:

Could not Analyze app/dev/js/out_front/day8/re_frame/tracing.cljc 
clojure.lang.Compiler$CompilerException: java.lang.Exception: namespace 'debux.common.macro-specs' not found, compiling:(debux/dbgn.clj:1:1)
Have I missed something obvious here?

robert-stuttaford16:04:01

@soulflyer if you lein deps :tree do you see debux somewhere in the output?

robert-stuttaford17:04:51

ok, so in your position, i’d track down the correct dependency by reading 10x source and manually include it in your project. if that fixes it, then you have the basis for a bug report for the 10x project 🙂

soulflyer17:04:03

hmm, rgrep isn't finding any mention of debux in the 10x source anywhere except in various .md files.

robert-stuttaford17:04:35

guess you’ll need to add it yourself then https://github.com/philoskim/debux

robert-stuttaford17:04:30

i’m literally on day one with re-frame - i plan to visit where you are tomorrow, so, thank you 🙂

soulflyer17:04:13

I think the 10x team forked debux and made some big changes. Adding the original back in might not have the desired effect...

robert-stuttaford17:04:39

does re-frame provide a more formal method for loading data when a component is displayed, beyond simply using a form-3 component with a :component-did-mount fn?

robert-stuttaford17:04:00

so, i’m talking specifically about the place where i call the dispatch that does the http call to populate the data for the view that’s just been displayed. e.g. i click a list item, go to the detail page. now i need all the detail data. when do i trigger that detail load? currently i have this, which works:

robert-stuttaford17:04:36

(defn load-event-for-editing [event-slug]
  (rf/dispatch [:bridge.event.ui/event-for-editing [:event/slug event-slug]]))

(defn edit-event [event-slug]
  (r/create-class
   {:display-name        "edit-event"
    :component-did-mount (fn [_]
                           (load-event-for-editing event-slug))
    :reagent-render
    (fn [_]
      (if-some [{:event/keys [title slug status start-date end-date
                              registration-close-date]}
                (get @(rf/subscribe [:bridge.event.ui/events]) event-slug)] …

ingesol13:04:43

Hi! This problem is the main reason for creating https://github.com/ingesolvoll/kee-frame . Just stumbled upon this message now while browsing 🙂

robert-stuttaford13:04:31

yep, i know about kee-frame. i’m this close to adopting it in bridge 🙂

ingesol13:04:34

That would obviously make me very happy

robert-stuttaford17:04:09

i’m wondering if there’s a more formal place to declare that ‘load this after mount’ event that i’m currently using react interop for

robert-stuttaford17:04:24

because i’d like to avoid using form-3 components if possible

akiroz18:04:24

@robert-stuttaford In a re-frame app, the data is usually loaded before the view is mounted so that view components can be as simple as possible. Usually you would have events that loads the data you want into the db and cause the related view to be mounted by setting the related states in the db.

mikethompson21:04:53

@robert-stuttaford that "load on mount" approach is *not* axiomatic re-frame

robert-stuttaford21:04:29

@mikethompson so how should i model this? this view could be directly triggered by a route, or by a dispatch due to clicking a link, so i don’t want to fire off the load at all of these call-sites. is there perhaps sample code around this sort of thing that i can read to osmose some patterns into my brain? 🙂 fwiw, i’m doing this as part of an intentional learning-in-the-open project. you can see all my code here: https://github.com/robert-stuttaford/bridge/compare/event-ui?expand=1

mikethompson21:04:09

Sorry, I started writing and then stopped because I thought "I have to write an FAQ on this"

nenadalm21:04:07

Wouldn't it be better to use defonce only for the live-intervals atom? Atom would then be accessible from the whole namespace, but on the other hand - you can modify the handler which can be properly hot reloaded?

robert-stuttaford21:04:30

that’s totally the right thing to do. i’ll read it when it’s ready 😉

robert-stuttaford21:04:46

in your own time, please — no rush from me!

mikethompson21:04:02

The above is quite a reasonable explanation

robert-stuttaford21:04:07

you get what i’m after, though, right?

robert-stuttaford21:04:26

i’ll chew on it, thanks

robert-stuttaford21:04:14

ok - so basically, i should always use the event dispatch mechanism, and chain together as many of those as i need. i guess the key thing i’m looking for is to be able to know when i need to trigger that load side-effect in the re-frame paradigm. i guess i have to let go of the coupling between the address bar and the intended state, and break it all down into events, and then let both the routing and normal nav gestures compose with those events. right now it’s all a little too conveniently tied to the routing

robert-stuttaford21:04:56

i do think a quick code sample covering the essential bits will go a long way to getting ones mind around the re-frame way here

mikethompson21:04:46

@soulflyer Are you using the right version of re-frame-10x for the version of React you are using?

mikethompson21:04:40

There is a version of re-frame-10x for React16 and another for React15. Choose wisely. Your error message doesn't seem related. But it is my first suspicion.

soulflyer23:04:43

tried it with both 0.3.0-1-react16 and 0.3.0 and still get the same error.

mikethompson21:04:30

Weird things can happen when you get it wrong.

mikethompson21:04:59

Note the use of the :http-xhrio effect from https://github.com/Day8/re-frame-http-fx

mikethompson22:04:12

@robert-stuttaford I've done the FAQ entry (it is not much more than what I have already pointed out): https://github.com/Day8/re-frame/blob/master/docs/FAQs/LoadOnMount.md

mikethompson23:04:00

@robert-stuttaford @soulflyer sorry about the re-frame-10x problems. @danielcompton is away for another day and he's best to figure out these two issues. I'm just not close enough to the code.

soulflyer23:04:57

@mikethompson No worries, I can wait