changed to use om.next

This commit is contained in:
David Mohl 2015-10-26 13:12:42 +09:00
parent e0d94dd2a1
commit ab8e7bfeeb
2 changed files with 29 additions and 10 deletions

View File

@ -2,7 +2,7 @@
(set! js/React (js/require "react-native/Libraries/react-native/react-native.js"))
(ns $PROJECT_NAME_HYPHENATED$.core
(:require [om.core :as om]))
(:require [om.next :as om :refer-macros [defui]]))
;; Reset js/React back as the form above loads in an different React
(set! js/React (js/require "react-native/Libraries/react-native/react-native.js"))
@ -17,16 +17,35 @@
;; Set up our Om UI
(defonce app-state (atom {:text "Welcome to $PROJECT_NAME$"}))
(defonce app-state (atom {:app/text "Welcome to $PROJECT_NAME$"}))
(defn widget [data owner]
(reify
om/IRender
(render [this]
(view {:style {:flexDirection "column" :margin 40}}
(text nil (:text data))))))
(defui WidgetComponent
static om/IQuery
(query [this]
'[:app/text])
Object
(render [this]
(let [{:keys [app/text]} (om/props this)]
(view {:style {:flexDirection "column" :margin 40}}
(text nil text)))))
(om/root widget app-state {:target 1})
;; om.next parser
(defmulti read om/dispatch)
(defmethod read :default
[{:keys [state]} k _]
(let [st @state]
(find st k)
(if-let [[_ v] (find st k)]
{:value v}
{:value :not-found})))
(def reconciler
(om/reconciler
{:state app-state
:parser (om/parser {:read read})}))
(om/add-root! reconciler WidgetComponent {:target 1})
(defn ^:export init []
((fn render []

View File

@ -5,7 +5,7 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.145"]
[org.omcljs/om "0.9.0"]
[org.omcljs/om "1.0.0-alpha8"]
[org.omcljs/ambly "0.6.0"]]
:plugins [[lein-cljsbuild "1.1.0"]]
:cljsbuild {:builds {:dev {:source-paths ["src"]