Created
December 16, 2016 20:39
-
-
Save fragamus/e0354311cfa0c9bd74aba6ff24887b86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; app state changes but no update | |
;; please help | |
(ns app.mutations | |
(:require [untangled.client.mutations :as m])) | |
(defmethod m/mutate 'app/choose-tab [{:keys [state]} _ {:keys [tab]}] | |
{:action (fn [] | |
(swap! state assoc :tabs [tab 1]) | |
)}) | |
(ns app.core | |
(:require | |
app.mutations | |
[untangled.client.core :as uc])) | |
(defonce app (atom (uc/new-untangled-client))) | |
(ns app.ui | |
(:require [om.dom :as dom] | |
[om.next :as om :refer-macros [defui]] | |
yahoo.intl-messageformat-with-locales | |
[untangled.client.core :as uc] | |
)) | |
(defui ^:once Main | |
static uc/InitialAppState | |
(initial-state [clz params] {:id 1 :type :main-tab :extra "MAIN STUFF"}) | |
static om/IQuery | |
(query [this] [:id :type :extra]) | |
Object | |
(render [this] | |
(let [{:keys [extra]} (om/props this)] | |
(dom/p nil "Main: " extra)))) | |
(def ui-main (om/factory Main {:keyfn :id})) | |
(defui ^:once Settings | |
static uc/InitialAppState | |
(initial-state [clz params] {:id 1 :type :settings-tab :args {:a 1}}) | |
static om/IQuery | |
(query [this] [:id :type :args]) | |
Object | |
(render [this] | |
(let [{:keys [args]} (om/props this)] | |
(dom/p nil "Settings: " (pr-str args))))) | |
(def ui-settings (om/factory Settings {:keyfn :id})) | |
(defui Switcher | |
static uc/InitialAppState | |
(initial-state [clz params] (uc/initial-state Main {})) | |
static om/IQuery | |
(query [this] {:main-tab (om/get-query Main) :settings-tab (om/get-query Settings)}) | |
static om/Ident | |
(ident [this {:keys [type id]}] | |
(do | |
(println "Switcher: [type id] =" (pr-str [type id])) | |
(try (/ 1 0) (catch Exception e (pst e))) | |
[type id] | |
) | |
) | |
Object | |
(render [this] | |
(let [{:keys [type] :as props} (om/props this)] | |
(case type | |
:main-tab (ui-main props) | |
:settings-tab (ui-settings props) | |
(dom/p nil "NO TAB"))))) | |
(def ui-switcher (om/factory Switcher)) | |
(defui ^:once Root | |
static uc/InitialAppState | |
(initial-state [clz params] {:ui/react-key "start" | |
:tabs (uc/initial-state Switcher {})}) | |
static om/IQuery | |
(query [this] [:ui/react-key {:tabs (om/get-query Switcher)}]) | |
Object | |
(render [this] | |
(let [{:keys [ui/react-key ]} (om/props this)] | |
(dom/div #js {:key react-key} | |
(dom/h4 nil "Header") | |
(dom/button #js { :onClick #(om/transact! this '[(app/choose-tab {:tab :main-tab})])} "Main") | |
(dom/button #js { :onClick #(om/transact! this '[(app/choose-tab {:tab :settings-tab})])} "Settings") | |
(ui-switcher :tabs))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment