Skip to content
Branch: master
Find file Copy path
Find file Copy path
3 contributors

Users who have contributed to this file

@smahood @mike-thompson-day8 @danielcompton
65 lines (45 sloc) 1.68 KB

Table Of Contents

What About Navigation?

How do I switch between different panels of a larger app?

Your app-db could have an :active-panel key containing an id for the panel being displayed.

When the user does something navigation-ish (selects a tab, a dropdown or something which changes the active panel), then the associated event and dispatch look like this:

  (fn [db [_ value]]
    (assoc db :active-panel value)))

  [:set-active-panel :panel1])

A high level reagent view has a subscription to :active-panel and will switch to the associated panel.

  (fn [db _]
    (:active-panel db)))

(defn panel1
 [:div  {:on-click #(re-frame/dispatch [:set-active-panel :panel2])}
        "Here" ])

(defn panel2
 [:div "There"])

(defn high-level-view 
  (let [active  (re-frame/subscribe [:active-panel])]
    (fn []
       [:div.title   "Heading"]
       (condp = @active                ;; or you could look up in a map
         :panel1   [panel1]
         :panel2   [panel2])])))

Continue to Namespaced Keywords to reduce clashes on ids.

Previous: Basic App Structure       Up: Index       Next: Namespaced Keywords

You can’t perform that action at this time.