Fork me on GitHub
#reagent
<
2016-05-19
>
sbmitchell01:05:54

garden does not let you do that either

sbmitchell01:05:08

it wont compile with multiple keys with the same name as far as I have seen

gadfly36102:05:51

@sbmitchell @ccann : you can do this in garden by using multiple maps (https://github.com/noprompt/garden/issues/6), for example: 1. lein new reagent-figwheel mygarden +garden 2. go to core.cljs and paste this in it

(ns mygarden.core
  (:require
   [reagent.core :as reagent]
   [garden.core :refer [css]]
   [garden.units :refer [px]]))


(defonce app-state
  (reagent/atom {}))

(defn page [ratom]
  (let [style
        (css
         [:.foo
          {:background "red"}
          {:background "-webkit-radial-gradient(circle, red, white, orange)"}])]
    [:div
     [:style style]
     [:p.foo "Foobar"]]))

(defn reload []
  (reagent/render [page app-state]
                  (.getElementById js/document "app")))

(defn ^:export main []
  (reload))
3. start figwheel, lein figwheel dev and navigate to localhost:3449 If you inspect the element, you will see both backgrounds are added

sbmitchell02:05:47

Thanks so multiple maps

sbmitchell02:05:02

quite odd that is the intended structure

sbmitchell02:05:11

or thats more of a workaround

sbmitchell02:05:21

🙂 but thanks nonetheless

ccann12:05:23

@gadfly361: thanks! That’s incredibly helpful. 🙂

escherize13:05:12

Dirty CSS - associative data should be associative.

gadfly36114:05:46

@lewix @sbmitchell Regarding with-meta vs create-class, found this old thread: https://clojurians-log.clojureverse.org/reagent/2016-03-18.html ... see @mikethompson comments

ccann14:05:06

@gadfly361: got it working, thanks again!

sbmitchell14:05:06

thanks @gadfly361 that is very helpful. I also use the form-3 style in all the components I need lifecycles. Glad to see there is a justification as far as the closed over data. I was thinking there had to be something

gadfly36114:05:52

Yeah, same - I didn't realize it was more than aesthetic until Mike mentioned that lol

martinklepsch17:05:36

I came to this channel multiple times to ask how I can access previous props passed to a component in lifecycle handlers, now I wrote this: https://www.martinklepsch.org/posts/props-children-and-component-lifecycle-in-reagent.html

martinklepsch17:05:40

feedback welcome

sbmitchell17:05:59

how you can access previous props? Like in component-will-receive-props where it has params [this [_ new-props]] and you need to use (reagent/props this) for the old ones and new-props would just be the map of new-props incoming

sbmitchell17:05:42

oh I see you are addressing if props arnt specfically a certain type like a map

sbmitchell17:05:09

I always make them maps so I guess I never really ran into that..I pretty much avoid multi-arg in favor of a single map

martinklepsch17:05:18

@sbmitchell: so all components you make have a single props arg with an extra key for :children?

sbmitchell18:05:58

@martinklepsch: Nope if I have components that have children I use & children then typically in the render its used as (into [:div] children)

sbmitchell18:05:48

so the structure Im using for like a slide panel component is like...`[SlidePanel panel-prop-map [LeftView props] [RightView props]]`

sbmitchell18:05:35

I dont use the children or need to reference the children in lifecycles because they just receive their own props and update at the same level as the containing component

sbmitchell18:05:56

now if I have a more dynamic need for the children where I give them props (i.e a data wrapping component perhaps) I would indeed pass them in a :children prop and then in the render id pass the props then

mattsfrey21:05:55

wondering if anyone has opinions on whether start-up conditions such as whether a user is logged in or whether critical data has been fetched should be coditionally checked inside of a top level component for all the view these checks are in place for, or if this should be handled at the router level ?