This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-29
Channels
- # admin-announcements (2)
- # beginners (10)
- # boot (253)
- # cider (11)
- # cljs-dev (26)
- # cljsjs (21)
- # cljsrn (7)
- # clojure (87)
- # clojure-berlin (13)
- # clojure-dusseldorf (5)
- # clojure-greece (7)
- # clojure-poland (11)
- # clojure-russia (189)
- # clojure-spec (31)
- # clojure-uk (86)
- # clojurescript (89)
- # cursive (15)
- # datavis (2)
- # datomic (57)
- # devcards (3)
- # dirac (92)
- # editors-rus (3)
- # emacs (4)
- # events (1)
- # funcool (30)
- # hoplon (3)
- # jobs-rus (6)
- # leiningen (1)
- # luminus (12)
- # mount (25)
- # off-topic (5)
- # om (43)
- # onyx (41)
- # perun (1)
- # proton (2)
- # protorepl (7)
- # re-frame (17)
- # reagent (34)
- # ring (13)
- # specter (1)
- # spirituality-ethics (1)
@lsnape: The re-com component can be seen demoed here: http://re-demo.s3-website-ap-southeast-2.amazonaws.com/#/input-text Coding can be seen here: https://github.com/Day8/re-com/blob/master/src/re_com/misc.cljs#L56-L58
But you son't have to use re-com. Take the idea and create your own input component for your own specific needs.
Is there an example of implementing the reagent ratom
in JavaScript? If not, how hard would it be?
@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
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
then inside myComponent this.props.myThing will exist and get updated whenever state.myThing changes
although not sure why you'd want to do any of this in js.. just looking at this code brings back horrible memories..
https://github.com/reactjs/reselect is the subscription library I was thinking of
@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.
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?
@lsnape: set :change-on-blur?
to false
@mikethompson: sorry, what I meant is why :change-on-blur?
is true
by default
Sensible default for many situations
@jmmk I guess mobxjs also provides a pattern similar to ratoms/reactions
(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]])]]]))
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"))