Fork me on GitHub
#reagent
<
2016-06-28
>
blance01:06:55

when passing multiple ratoms to a component, do you define it as (defn some-component [props children this] ) and pass everying inside the props map? or (defn comp [arg1 arg2 arg3 arg4...])

blance01:06:10

is the first one the only correct way of defining component which needs more than one ratom argument?

kauko04:06:40

is that a React thing to pass children and this as parameters? What's this?

blance04:06:03

@kauko: I read that at some reageng tutorial online.

blance04:06:21

In fact, I'm trying to use leaflet, a stateful JS library with reagent and re-frame

blance04:06:47

Thus I need to modify the mutable js object in :component-did-update

blance05:06:43

and when I try to pass in as (defn comp [arg1 arg2 arg3...]), even though the corresponding on-update function is called when arg3 changed, I still can't see the updated value

blance05:06:42

However, If I pass in a prop map, I could do (reagent/props component) to get the updated props

blance05:06:29

Though this feels unnatural to me, I don't understand why is my on-update function called but no update can be seen

kauko05:06:59

When you say "you can't see the updated value", what do you mean? If you add logging to on-update, what do you see? What about if you add logging to your render function?

kauko05:06:16

Or do you just mean that once the component is rendered, it doesn't look like it updated?

kauko05:06:39

One common mistake with reagent is that you don't use reagent's atoms, but instead clojurescript's normal atoms

kauko05:06:52

but since your on-update is being called, that probably is not the case

blance06:06:52

Im using reframe's subscribe, which uses ratom i believe.

blance06:06:32

So reframes db is changed. I can see that from re reading the db

blance06:06:24

But the argument is not changed, even though it subscribes ro reframe's db

blance06:06:10

I can post some code snippet if that help explains it?

mikethompson07:06:19

@roberto: Really odd that you get that message. Just to state the obvious, you are doing a (:require [reagent.ratom]), right?

roberto12:06:41

@mikethompson: this is the code:

(ns buttons.ui.subscriptions
  (:require [buttons.ui.edb :as edb]
            [buttons.ui.entities :as entities])
  (:require-macros [reagent.ratom :refer [reaction]]))

(defn links
  [app-db]
  (reaction
   (entities/get-links @app-db)))

(def subscriptions {:links links})

mihaelkonjevic12:06:03

@roberto this looks sane to me, what is your cljs version? It seems that macro loading changed https://github.com/clojure/clojurescript/commit/783001a6786f8dca4a13fdeadc995716903b07f9

roberto12:06:09

for what its worth, I’m not getting the warning anymore. It was probably a figwheel issue because it stopped once I killed figwheel, ran lein clean and started again

Petrus Theron14:06:19

Fetching data for a component: best done in :component-will-mount? Or has another best practice arisen?

blance16:06:11

@mikethompson: I've read that and that's how I build my component. However, the example only has 1 argument passed in, and it seems passing multiple arguments is not as trivial as I thought.

tawus22:06:47

@pesterhazy: Thanks. Apologies for later response. Slack has not been working properly for me.

mikethompson22:06:51

@petrus: I don't believe in using :component-will-mount (for loading data). My take: https://github.com/Day8/re-frame/wiki/Subscribing-To-A-Database

mikethompson22:06:02

@petrus: oops, I've just realised this is the reagent channel, not the re-frame one. So my re-frame solution given above may be too specific. But I'll leave it there for what it is worth.

mikethompson22:06:47

@blance: what part of multiple arguments is hard? (it shouldn't be hard) I'm guessing here, but did you see the link to: https://www.martinklepsch.org/posts/props-children-and-component-lifecycle-in-reagent.html

blance23:06:45

@mikethompson: Thanks! that solves my problem.

blance23:06:51

since you are so nice, could you point me to some resources regarding testing in cljs? similar to jasmine, eslint, karma, and others in the JS world.

blance23:06:58

Thanks:grinning: