Fork me on GitHub
#reagent
<
2016-07-29
>
mikethompson00:07:25

But you son't have to use re-com. Take the idea and create your own input component for your own specific needs.

jmmk01:07:55

Is there an example of implementing the reagent ratom in JavaScript? If not, how hard would it be?

mattsfrey01:07:55

redux uses a store which is a js object but functions the same as that basically

jmmk01:07:25

@mattsfrey: true, I remember looking at that code before. And the redux subscription lib (forget the name atm...) handles focusing in on particular elements' updates like reaction

jmmk01:07:35

I'll take a look at those

mattsfrey01:07:38

redux has a 'connect' function that you wrap your components in and it will inject a piece of the state you select to monitor into the props everytime it updates

mattsfrey01:07:06

connect(state => state.myThing)(React.createComponent(...

mattsfrey01:07:47

then inside myComponent this.props.myThing will exist and get updated whenever state.myThing changes

mattsfrey01:07:51

although not sure why you'd want to do any of this in js.. just looking at this code brings back horrible memories..

jmmk01:07:02

not necessarily vanilla js, but maybe one of the typed compile-to-js languages

jmmk01:07:59

https://github.com/reactjs/reselect is the subscription library I was thinking of

lsnape09:07:03

@danielcompton @mikethompson thanks for letting me know about re-com. It was already being used in the project for bits and pieces but not for textarea components. Substituting the offending textarea with a re-com component does indeed make the problem go away, yet I have to confess I’m none the wiser as to why this was happening in the first place: to my surprise it was the (.. e -target -value) values that were being scrambled; the re-frame event handlers and rendering were being called in the expected order.

lsnape09:07:50

Also, I’d like to know why by default the on-change handler is only invoked when the element is blurred? Is it just for efficiency reasons?

mikethompson11:07:12

@lsnape: set :change-on-blur? to false

lsnape12:07:36

@mikethompson: sorry, what I meant is why :change-on-blur? is true by default

mikethompson14:07:37

Sensible default for many situations

metametadata14:07:14

@jmmk I guess mobxjs also provides a pattern similar to ratoms/reactions

thomas21:07:22

Hi, does anyone have an example somewhere of a table with reagent….

thomas21:07:48

I would like to table to get updated when my atom gets update though.

gadfly36121:07:38

@thomas:

(defn table-example [ratom]
  (let [foos (:foos @ratom)]
    [:table
     [:thead
      [:tr
       [:th "Header 1"]
       [:th "Header 2"]]
      [:tbody
       (for [{:keys [id bar baz]} foos]
	    ^{:key id}
	    [:tr
	     [:td bar]
	     [:td baz]])]]]))

thomas21:07:07

hmm I must be doing something wrong in that case...

thomas21:07:18

let me investigate some more. Thanks though

thomas21:07:52

ok, silly question… how/where do you call this func?

gadfly36121:07:09

You'd call it like any other reagent component, using square brackets. For example (untested)

(defonce app-state
  (reagent/atom
    {:foos [{:id 1 :bar "xx1" :baz "yy1"}
          {:id 2 :bar "xx2" :baz "yy2"}
          {:id 3 :bar "xx3" :baz "yy3"}]}))

(defn table-example [ratom]
  (let [foos (:foos @ratom)]
    [:table
     [:thead
      [:tr
       [:th "Header 1"]
       [:th "Header 2"]]
      [:tbody
       (for [{:keys [id bar baz]} foos]
        ^{:key id}
        [:tr
         [:td bar]
         [:td baz]])]]]))

(defn page [ratom]
  [:div
   [:h1 "This is a Table!"]
   [table-example ratom]])

(reagent/render [page app-state]
                (.getElementById js/document "app"))

thomas21:07:17

ok, I think I have that… more investigation needed.

thomas21:07:27

thank you for your help though

gadfly36121:07:53

no problem, happy to help

thomas22:07:07

ok got it working now…. 🙂 turned out I didn’t have a vector of maps DOH

gadfly36122:07:48

Glad you got it workin!