Created
December 1, 2015 08:35
-
-
Save nodename/1a39441781c7bcfae1fe to your computer and use it in GitHub Desktop.
messed up om/next with react native
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
(ns hello.core | |
(:require [om.next :as om :refer-macros [defui]])) | |
(enable-console-print!) | |
(def React (js/require "react-native")) | |
(def AppRegistry (aget React "AppRegistry")) | |
(def StyleSheet (aget React "StyleSheet")) | |
(def create-element (aget React "createElement")) | |
(defn view | |
[opts & children] | |
(apply create-element | |
(aget React "View") | |
(clj->js opts) | |
children)) | |
(defn text | |
[opts & children] | |
(apply create-element | |
(aget React "Text") | |
(clj->js opts) | |
children)) | |
(defonce app-state | |
(atom {:welcome/msg "Welcome to React Native!"})) | |
(def styles (.create StyleSheet (clj->js { | |
:container {:flex 1 | |
:justifyContent "center" | |
:alignItems "center" | |
:backgroundColor "#F5FCFF"} | |
:welcome {:fontSize 20 | |
:textAlign "center" | |
:margin 10} | |
:instructions {:textAlign "center" | |
:color "#333333" | |
:marginBottom 5}}))) | |
(defn renderer | |
[msg] | |
(view {:style (aget styles "container")} | |
(text {:style (aget styles "welcome")} | |
msg) | |
(text {:style (aget styles "instructions")} | |
"To get started, edit src/hello/core.cljs") | |
(text {:style (aget styles "instructions")} | |
"Shake or press menu button for dev menu"))) | |
#_(def create-class (aget React "createClass")) | |
#_(def AwesomeProject (create-class #js {:render render})) | |
(defui AwesomeProject | |
static om/IQuery | |
(query [this] | |
'[:welcome/msg]) | |
Object | |
(render [this] | |
(let [{:keys [welcome/msg]} (om/props this)] | |
(renderer msg)))) | |
(defn read | |
[{:keys [state] :as env} key params] | |
(let [st @state] | |
(if-let [[_ v] (find st key)] | |
{:value v} | |
{:value :not-found}))) | |
(def reconciler | |
(om/reconciler | |
{:state app-state | |
:parser (om/parser {:read read}) | |
:root-render #(.render React %1 %2) | |
:root-unmount #(.unmountComponentAtNode React %)})) | |
#_(def register-component (aget AppRegistry "registerComponent")) | |
#_(register-component "AwesomeProject" (fn [] AwesomeProject)) | |
(om/add-root! reconciler AwesomeProject 1) | |
(defn ^:export init [] | |
((fn render [] | |
(.requestAnimationFrame js/window render)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment