Fork me on GitHub
#re-frame
<
2016-02-23
>
escherize02:02:29

A talk (partly) about re-frame at the react conf: http://conf.reactjs.com/schedule.html

hugobessaa11:02:17

Nice! Will watch

lsenta21:02:12

Hey guys, I have a weird bug, I'm under the impression re-frame/reagent does not update the ui for a component parameter change:

(defn base [id]
  (let [show-db-summary (subscribe :show-db-summary?)]
    (fn []
      [:div#main {:className "sidebar-l sidebar-o side-scroll header-navbar-fixed"}
       [side-overlay]
       [sidebar]
       [header]
       (if @show-db-summary
         [db-summary]
         (case id
           :a [a/main]
           :b [b/main]
           (do (log/error "Unknown module:" id)
               (dispatch :navigate :404))))
       [footer]])))


(defn main []
  (let [module (subscribe :active-module)]
    (fn []
      (cond
        (= @module :welcome) [welcome/main]
        (contains? #{:a :b} @module) [base @module]
        :else [module-404]))))

lsenta21:02:42

when I switch between :a and :b, the [base id] is not updated

lsenta21:02:09

the rest of the system works fine, I display the :active-module in the header, it's updated correctly

lsenta21:02:13

Am I missing something?

lsenta21:02:50

(it renders correctly when figwheel reloads)

nberger22:02:26

@lsenta: I didn't see all the details, perhaps there's something else missing, but one thing is that you need to put id in the args list of the inner fn in your base component. So it would be:

(defn base [id]
  (let [show-db-summary ...]
    (fn [id]
      ...)))

mikethompson22:02:18

@lsenta: nberger has identified the bug, but that codes is not very re-frame-y

mikethompson22:02:51

the way that it does an imperative (dispatch :navigate :404)

mikethompson22:02:24

That is an attempt to change the state of the app. That decision should be in an event handler.

mikethompson22:02:44

Views just render the current state

mikethompson22:02:40

(and dispatch in response to external events) They don't make "decisions about state changes"