Я использую инфраструктуру re-frame
cljs, которая использует reagent
в качестве своей библиотеки представлений. У меня есть компонент графа nvd3
, который я хочу обновлять при обновлении его подписок.
К сожалению, граф никогда не обновляется после первоначального вызова :component-did-mount
. :component-will-update
никогда больше не вызывается после первоначального рендеринга.
Я хочу, чтобы график обновлялся, поскольку подписка уведомляет компоненты о том, что она слушает изменения.
Вот компонент графа-контейнера:
(defn weight-graph-container
[]
(let [weight (subscribe [:weight-change])
bodyfat (subscribe [:bodyfat-change])
weight-amount (reaction (get @weight :amount))
weight-unit (reaction (get @weight :unit))
bf-percentage (reaction (get @bodyfat :percentage))
lbm (reaction (lib/lbm @weight-amount @bf-percentage))
fat-mass (reaction (- @weight-amount @lbm))]
(reagent/create-class {:reagent-render weight-graph
:component-did-mount (draw-weight-graph @lbm @fat-mass "lb")
:display-name "weight-graph"
:component-did-update (draw-weight-graph @lbm @fat-mass "lb")})))
Вот компонент графика:
(defn draw-weight-graph [lbm fat-mass unit]
(.addGraph js/nv (fn []
(let [chart (.. js/nv -models pieChart
(x #(.-label %))
(y #(.-value %))
(showLabels true))]
(let [weight-data [{:label "LBM" :value lbm} {:label "Fat Mass" :value fat-mass}]]
(.. js/d3 (select "#weight-graph svg")
(datum (clj->js weight-data))
(call chart)))))))
Наконец, вот компонент, в который отображается график:
(defn weight-graph []
[:section#weight-graph
[:svg]])
Что мне не хватает? Спасибо за любую помощь.