This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-17
Channels
- # 100-days-of-code (4)
- # announcements (4)
- # aws (2)
- # beginners (88)
- # cider (1)
- # cljsrn (9)
- # clojure (126)
- # clojure-conj (4)
- # clojure-dev (8)
- # clojure-greece (1)
- # clojure-italy (37)
- # clojure-nl (3)
- # clojure-spec (13)
- # clojure-uk (91)
- # clojurescript (392)
- # clojurewerkz (1)
- # clojutre (10)
- # core-async (6)
- # cursive (5)
- # data-science (1)
- # datomic (41)
- # emacs (21)
- # events (1)
- # figwheel-main (52)
- # fulcro (2)
- # hyperfiddle (4)
- # jobs (3)
- # jobs-discuss (9)
- # luminus (3)
- # lumo (9)
- # mount (1)
- # nyc (1)
- # off-topic (73)
- # other-languages (6)
- # pedestal (8)
- # portkey (2)
- # re-frame (9)
- # reagent (8)
- # rum (17)
- # shadow-cljs (38)
- # sql (19)
- # tools-deps (18)
- # yada (4)
I am creating a reagent form and trying to update an atom which is a map. The value I want to update is itself a map so I want to do (reset! com-form update-in [:new-price :quantity] (-> evt .-target .-value))
. The threading macro is confusing me but there must be a way to do this.
@dfcarpenter you want swap!
not reset!
your threading macro is correct (also if it ever confuses you, run the form through macroexpand
)
(def com-form (r/atom {:name ""
:desc ""
:new-price nil
:prices []
:assets []}))
(defn new-component []
(let [comform @com-form]
[:div
[:div
[:div
[:input.input {:type "text"
:name "name"
:placeholder "name"
:value (get comform :name)
:on-change #(swap! com-form update :name (-> % .-target .-value))}]
[:button {:on-click #(swap! com-form assoc :new-price {:pricingType ""
:currency ""
:costValue 0
:quantity 0})} "Add Price"]
]]]))
I keep getting tons of errors, specifically
Uncaught TypeError: f.call is not a function
at core.cljs:5283
at Function.cljs$core$IFn$_invoke$arity$3 (core.cljs:5283)
at Object.cljs$core$ISwap$_swap_BANG_$arity$4 (ratom.cljs:146)
at Function.cljs$core$IFn$_invoke$arity$4 (core.cljs:856)
at Function.cljs$core$IFn$_invoke$arity$4 (core.cljs:4470)
at eval (views.cljs:63)
at HTMLUnknownElement.callCallback (react-dom.development.js:101)
at Object.invokeGuardedCallback (react-dom.development.js:139)
at Object.invokeGuardedCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:202)
if you run (swap! (reagent/atom {:foo 1}) update :foo 2)
in a cljs repl you’ll get that f.call is not a function
error
@lee.justin.m Ahh, thanks!