Fork me on GitHub
#re-frame
<
2020-05-12
>
andre03:05:51

I know, I mean, I'm old school, I just feel better when I create subs outside 🙂

andre03:05:10

i don't see any benefits from using cached subs

p-himik03:05:16

The benefit is simpler code and subscription reuse. If using form-2 components is your personal preference, that's OK. But please don't tell people that "that's the rule".

👍 4
andre03:05:29

sorry i missed one word , that's my rule 🙂

👍 4
Franklin09:05:18

I get this error when trying to inspect app state from figwheel's repl:

Franklin09:05:32

#object[Error Error: Vector's key for assoc must be a number.]
   cljs$core$IAssociative$_assoc$arity$3 (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:5550:14)
   cljs.core/-assoc (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:630:17)
   Function.cljs$core$IFn$_invoke$arity$3 (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:1972:8)
   cljs$core$assoc (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:1965:1)
   sval (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:3399:18)
   cljs$core$ISeqable$_seq$arity$1 (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:3453:12)
   cljs$core$seq (jar:file:/home/user/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/core.cljs:1210:25)

Franklin09:05:18

what could be causing this? I have googled around and can't seem to find any answers

Franklin09:05:16

I updated reagent and re-frame and this error just went away 😮

Franklin09:05:23

I don't feel like I'm in control here 😆

mikethompson09:05:05

Can you provide more information about what you mean by inspect app stage

mikethompson09:05:20

What exactly did you do in figwheel?

Franklin09:05:31

I meant inspect app state...

Franklin09:05:48

This is what I did:

Franklin09:05:51

app:cljs.user=> (require '[re-frame.core :as re-frame])
nil
app:cljs.user=> @re-frame.db/app-db

mikethompson10:05:52

Your stack trace seems to indicate that you were using assoc, perhaps on a vector

Lu10:05:49

You can assoc in a vector i.e. (assoc [] 0 1)

Lu10:05:50

The error is saying that the index where you are associng must be an int. You can't do in fact: (assoc [] :hello 3)

Lu10:05:48

It's weird to use assoc for vectors, yet I find myself doing it in some cases when the vector is somewhere nested in a map i.e.:

(assoc-in {:a {:b [1 2 3]}} [:a :b 0] :replacement-value-at-index-0)

Franklin11:05:14

@lucio But this stack trace doesn't really say where in my code I'm making such a mistake in my code... it's really hard to find it

Franklin11:05:36

Also, these two lines don't seem to be using assoc anywhere...

Lu11:05:09

Yeah it's very cryptic

thelittlesipper14:05:17

@p-himik I just saw your response regarding my re-frame subs question. And just to be clear - because I've been getting different opinions on this from different folks - you're saying that in the below (contrived) example - deref'ing outside the component - is ok?

;; only immutable data gets passed in to the component
(defn my-component [s] [:div s])

;; this function is the "view" that gets rendered and may contain many components
(defn my-panel []
  [:<>
    [my-component @(rf/subscribe [::subs/my-sub])]]))
Just to give context, I've been deref'ing all of my subs outside of my components (^similar to the example above) in the "panels"/overall-views to keep the components themselves pure, easily-testable, and reusable across projects. It was only recently that someone pointed out to me that deref'ing outside of the component/leaf-nodes may impact performance poorly. And so, before I embark in refactoring a ton of code I'd like certain verification of the aforementioned point.

lilactown15:05:01

best performance tip I've ever gotten: measure first

lilactown15:05:13

if you're not experiencing performance issues, don't worry about it

lilactown15:05:21

if you are, measure it and see where it's slow

👍 4
thelittlesipper15:05:19

That is a very good point indeed, and I will definitely do that. But, I'd still like to know right off the bat if I'm driving on the wrong side of the road.

lwhorton15:05:15

a while back reframe introduced some sugar around derefing in the different form-1/2/3 components. i dont particularly like it, but its there

thelittlesipper15:05:21

Thanks, this helps 👍

dpsutton15:05:27

^ i learned that the other day 🙂