Fork me on GitHub
Pepijn de Vos09:04:28

With a from-2 component, what's the significance of the arguments of the inner and outer function? I think the docs tell you that they should be the same, but I've seen code where the inner just did not take arguments.


The outer function sets the arguments upon entry, the inner function sets them on rerender?

Pepijn de Vos10:04:36

Yea but what happens when the list of arguments is not the same?


basically you would lose the ability to update an argument in a rerender. If I add an extra argument on the outer function but not in the rerender function it will not update in the rerender I guess. Not an expert.

Pepijn de Vos10:04:24

Mostly what I've seen is where the inner fn just takes no args... maybe that's valid if you only use the args in the outer fn? not sure


here is a scenario that would fail I think

(defn wont-update [x]
  (let [] ;; here you would prob declare some inner state with an r/atom
    (fn []
      (println x))))

;; (wont-update 3) -> 3
;; (let [input (r/atom 2)]
     (wont-update @input) ;; -> 2
     (reset! input 5)
     (wont-update @input) ;; -> 2

Pepijn de Vos10:04:07

Yea using x in the inner fn while not passing it to the inner function is clearly wrong.


with-let helps a lot to unify the args.


Anyone aware of any good patterns/libraries for partitioning a map (example with a reagent element)

(defn my-element [{:keys [key1 key2] :as props} & children]
   ; Do stuff with key1 and key2

   ; Pass down remaining props to :div
   [:div (dissoc props :key1 :key2) ...])
Wanted to ask before I write my own defn wrapper macro that has support for something like [{:keys [key1 key2] :as props :remaining other-props} ...}


Please avoid cross-posting. There are almost 10x as many people in #clojurescript and I'd say your question belongs more to #clojure even because it's really generic.