Fork me on GitHub
#re-frame
<
2017-07-01
>
fabrao01:07:40

Hello all, I´m trying to use http://olifolkerd.github.io/tabulator/ with re-frame and reagent, but I don´t know why the data is not being updated

(defn tabulator-mount [this]
  (.tabulator (js/$ (rg/dom-node this)) (clj->js {:height 500
                                                  :fitColumns true})))

(defn tabulator-render [dados]
  [:table
   [:thead
    [:tr
     [:th {:width "200"} "Código"]
     [:th "Descrição"]
     [:th "Preço"]
     [:th "Estoque"]
     ]]
   [:tbody
    (for [dado dados]
      ^{:key (:codProduto dado)}
      [:tr 
       [:td (:codProduto dado)]
       [:td (:descricao dado)]
       [:td (:preco dado)]
       [:td (:estoque dado)]
       ]
      )]]
  )

(defn tbl-dt [dados]
  (rg/create-class
   {:reagent-render #(tabulator-render dados)
    :component-did-mount tabulator-mount}))
(defn ui-comp []
[:div [tbl-dt @(rf/subscribe [:dados-produto])]])

fabrao01:07:52

When I dispatch other datas to :dados-produto it´s not updating the datatable, what´s wrong?

fabrao01:07:18

Can I use any jQuery component with reagent and re-frame?

lsenta09:07:36

@fabrao your render function has a closure over the initial parameter

lsenta09:07:52

try with :reagent-render #(tabulator-render %)

lsenta09:07:26

then drop the lambda if it makes sense 😉

lsenta09:07:43

fwiw that's a weakness of cljs, reagent will call the lambda with a parameter and you won't see any error. because in javascript:

(function() { console.log('helloworld'); })('some', 'parameters', 'no one cares about')
is fine.

lsenta09:07:21

(in clj you'd get a wrong arity exception)

souenzzo17:07:04

How to use graphql with re-frame?