This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-07
Channels
- # beginners (19)
- # cider (20)
- # cljs-dev (2)
- # cljsjs (2)
- # clojure (61)
- # clojure-spec (13)
- # clojure-uk (12)
- # clojurescript (12)
- # core-typed (1)
- # cursive (16)
- # data-science (30)
- # datomic (37)
- # fulcro (8)
- # hoplon (7)
- # jobs-discuss (1)
- # onyx (21)
- # planck (18)
- # protorepl (1)
- # re-frame (2)
- # reagent (1)
- # shadow-cljs (6)
- # tools-deps (4)
@lwhorton That's because subscription handlers receive more than one argument. Your way of doing things actually should've been producing this result at all times when db
doesn't have the required key.
Consider (:a {} 7)
- it returns 7
. The value after the map is the default value, just like in get
.
👍 4
hi everyone. i have a sortable component, that looks like this
(defn render
"this function renders a sortable list.
it will pass down draggable props to
the component as a first argument."
[{order :order}]
(let [state (r/atom {:order order})]
(fn [{:keys [items order on-reorder item-renderer container-class is-updating?]}]
(let [items (vec items)]
(into [:div.sortable-list {:class container-class}
(when is-updating? [loading])]
(for [[id position] (map vector (:order @state) (range))]
(when-let [item (first (filter #(= id (:id %)) items))]
[item-renderer
{:key id
:class [(sortable-list__item)
(when is-updating?
(sortable-list__item-updating))
(when (= id (:drag-index @state))
(sortable-list__item-dragging))]
:draggable true
:on-drag-start #(swap! state assoc :drag-index id)
:on-drag-over (fn [e]
(.preventDefault e)
(swap! state assoc
:drag-over position)
(swap! state update
:order change-position
(:drag-over @state)
(:drag-index @state)))
:on-drag-leave #(swap! state assoc :over :empty)
:on-drag-end (fn []
(swap! state dissoc :drag-index :drag-over)
(when on-reorder (on-reorder (:order @state))))}
item])))))))
basically it receives a map that has an order. and then it saves it in a local state. and once the re-order happens, on-reorder
function is called that saves the new order on the BE. it all works fine until I add a new item to this list. the problem is that because this is a second type reagent component and order
is saved outside, it doesn’t get updated. what could be a solution to such case?