This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-31
Channels
- # admin-announcements (23)
- # announcements (3)
- # beginners (59)
- # boot (122)
- # clojure (117)
- # clojure-berlin (3)
- # clojure-dev (3)
- # clojure-italy (3)
- # clojure-japan (10)
- # clojure-russia (69)
- # clojurebridge (12)
- # clojurescript (183)
- # clojutre (14)
- # code-reviews (4)
- # core-async (79)
- # core-logic (18)
- # core-matrix (1)
- # cursive (7)
- # datascript (1)
- # datomic (18)
- # editors (3)
- # events (18)
- # hoplon (20)
- # ldnclj (24)
- # luminus (1)
- # off-topic (1)
- # other-lisps (1)
- # re-frame (12)
- # reagent (104)
What do people think of re-frame?
caskolkm: nice, thanks.
@caskolkm @pupeno it is more than fine to ask opinion of re-frame in this channel, since re-frame is a library for reagent and you may get more mixed opinions in this channel than you would in re-frame channel. That said, I love re-frame!
@gadfly361: it was just a hint
having trouble getting a reaction
to trigger inside a document.ready
callback
(defn weights-page-did-mount []
(.ready (js/$ js/document)
(fn []
...
;; TODO this does not fire for some reason
(reaction
(let [validator (.data (js/$ "#form-search") "bootstrapValidator")]
(print-state (str "revalidating due to changed " @max-total-weight))
(.revalidateField validator "in-total-weight"))))))
I can't seemt to put my hands on an example of a select
component (load from ajax, on-select swap a value into another component). Any pointers?
seems like it would be non-trivial with re-frame if on-select
you dispatch, and you also have a subscriber for changes on that select option.
I started doing just reagent and when I started feeling some pain, I spent some time on re-frame
but I was working on a side project that is disposable, so I could start from scratch
even if you donāt use re-frame, the concept should help you organize the state in your vanilla reagent app
hmm, I donāt recall the event off the top of my head. Is it on-change or on-select?
grrrrrrr.... that change was easy, but restarting figwheel broke on a class not found (from my server-side java code!)
anyone wants to have a look at a sample project that fails to trigger a reaction
from a document.ready
callback?
https://github.com/ulsa/bvtest
in Hoplon, I got errors in the cell=
if I tried it outside ready, so I placed it there and it worked nicely
https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount
eg: https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/bootstrap-datepicker
anyway, not sure ready is the problem, since it's not triggering outside either; am I missing something about reactions?
Yeah, react life cycles are preferred. I should check that recipe, waiting for document ready AND using component-did-mount might be unnecessary.
changed back to component-did-mount, just a defn, it compiles, but no change from earlier
I suppose component-did-mount is enough, since that point guarantees a dom representation of the component.
first tab should be changed from invalid to valid, but that doesn't happen; works in hoplon
another reaction
should look at max total and trigger revalidate, but I can't see that it does anything
manually going back to first tab revalidates due to onTabShow
, so revalidate itself works
this is a lot of code, a little hard for me to follow, but one of the first things that jumps to me is that your reaction
is āoutsideā.
so I would use form-2: and do the reactions inside a let, similar to how it is done in re-frame.
(defn weights-page-component []
(let [max-total-weight (reaction (if (= "B" (:eligibility @state)) 4000 3000))]
(create-class {:component-did-mount weights-page-did-mount
:render (fn [] (render-here)))
yeah, that way, max-total-weight is within the same scope as the function that renders
(defn main-panel
[]
(let [store (subscribe [:new-shop])
loc (subscribe [:new-shop/location])
loading? (subscribe [:new-shop/loading?])]
(create-class
{:component-did-mount #(dom/register-mdl-components)
:reagent-render
(fn []
[:div
[:section {:class "section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp"}
[title-view]]
[:section {:class "section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp"}
(if @loading?
[:div {:class "mdl-card mdl-cell mdl-cell--12-col-desktop mdl-cell--8-col-tablet mdl-cell--4-col-phone"}
[:section {:class "mdl-card__supporting-text"}
[:h5 "Acquiring location coordinates...."]]]
[registered-form])]])})))
the subscribes can be translated to something like loc (reaction (something something)
and from re-frameās docs:
(defn items-list ;; Form-2 component - outer, setup function, called once
[]
(let [items (subscribe [:sorted-items]) ;; <-- subscribe called with name
num (reaction (count @items)) ;; Woh! a reaction based on the subscription
top-20 (reaction (take 20 @items))] ;; Another dependent reaction
(fn []
[:div
(str "there's " @num " of these suckers. Here's top 20") ;; rookie mistake to leave off the @
(into [:div ] (map item-render @top-20))]))) ;; item-render is another component, not shown
I guess I can wrap render, did-mount and create-class in a closure that let's max-total-weight
okay, i got to step away. Iāve been fighting with aws all day long and Iām frustrated.
even if you donāt use it, but the concepts will help you with what you are trying to do
Moved all state inside component, as suggested, which makes it better I guess, but still no trigger on the revalidate reaction
. I'm probably missing something about how reaction
works compared to Hoplon's cell=
.
Even if the actual revalidation didn't cause a DOM update due to some React thing, I figure the print
called from the reaction
should be seen in the log, but I don't see it.
@ulsa: reactions are tricky if they are not derefed inside a render function, as I've written here https://github.com/reagent-project/reagent/issues/116
using reagent.ratom/run!
instead of reaction
for your validation reaction should fix it