move app-state and reconciler to separate namespace

This commit is contained in:
Artur Girenko 2016-02-11 00:24:17 +01:00
parent ca43c940fb
commit 59edcd3591
4 changed files with 26 additions and 23 deletions

View File

@ -48,7 +48,7 @@ interfaceConf =
sources:
ios: ["core.cljs"]
android: ["core.cljs"]
common: []
common: ["state.cljs"]
other: [["support.cljs","re_natal/support.cljs"]]
deps: ['[org.omcljs/om "1.0.0-alpha28" :exclusions [cljsjs/react cljsjs/react-dom]]'
'[natal-shell "0.1.6"]']

View File

@ -2,15 +2,14 @@
(:require-macros [natal-shell.components :refer [view text image touchable-highlight]]
[natal-shell.alert :refer [alert]])
(:require [om.next :as om :refer-macros [defui]]
[re-natal.support :as sup]))
[re-natal.support :as sup]
[$PROJECT_NAME_HYPHENATED$.state :as state]))
(set! js/React (js/require "react-native"))
(def app-registry (.-AppRegistry js/React))
(def logo-img (js/require "./images/cljs.png"))
(defonce app-state (atom {:app/msg "Hello Clojure in iOS and Android!"}))
(defui AppRoot
static om/IQuery
(query [this]
@ -27,26 +26,9 @@
:onPress #(alert "HELLO!")}
(text {:style {:color "white" :textAlign "center" :fontWeight "bold"}} "press me"))))))
(defmulti read om/dispatch)
(defmethod read :default
[{:keys [state]} k _]
(let [st @state]
(if-let [[_ v] (find st k)]
{:value v}
{:value :not-found})))
(defonce reconciler
(om/reconciler
{:state app-state
:parser (om/parser {:read read})
:root-render sup/root-render
:root-unmount sup/root-unmount}))
(defonce RootNode (sup/root-node 1))
(defonce app-root (om/factory RootNode))
(defn init []
(om/add-root! reconciler AppRoot 1)
(om/add-root! state/reconciler AppRoot 1)
(.registerComponent app-registry "$PROJECT_NAME$" (fn [] app-root)))

View File

@ -1,6 +1,7 @@
(ns ^:figwheel-no-load env.$PLATFORM$.main
(:require [om.next :as om]
[$PROJECT_NAME_HYPHENATED$.$PLATFORM$.core :as core]
[$PROJECT_NAME_HYPHENATED$.state :as state]
[figwheel.client :as figwheel :include-macros true]))
(enable-console-print!)
@ -8,7 +9,7 @@
(figwheel/watch-and-reload
:websocket-url "ws://localhost:3449/figwheel-ws"
:heads-up-display true
:jsload-callback #(om/add-root! core/reconciler core/AppRoot 1))
:jsload-callback #(om/add-root! state/reconciler core/AppRoot 1))
(core/init)

View File

@ -0,0 +1,20 @@
(ns $PROJECT_NAME_HYPHENATED$.state
(:require [om.next :as om]
[re-natal.support :as sup]))
(defonce app-state (atom {:app/msg "Hello Clojure in iOS and Android!"}))
(defmulti read om/dispatch)
(defmethod read :default
[{:keys [state]} k _]
(let [st @state]
(if-let [[_ v] (find st k)]
{:value v}
{:value :not-found})))
(defonce reconciler
(om/reconciler
{:state app-state
:parser (om/parser {:read read})
:root-render sup/root-render
:root-unmount sup/root-unmount}))