mirror of
https://github.com/status-im/re-natal.git
synced 2025-01-24 19:39:32 +00:00
add interface 'reagent6' which uses reagent-0.6.0-alpha and re-frame-0.7.0
This commit is contained in:
parent
b0b34b075b
commit
091bf38166
@ -46,6 +46,19 @@ interfaceConf =
|
||||
shims: ["cljsjs.react"]
|
||||
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.ios.core)'
|
||||
sampleCommand: '(dispatch [:set-greeting "Hello Native World!"])'
|
||||
'reagent6':
|
||||
cljsDir: "cljs-reagent6"
|
||||
sources:
|
||||
ios: ["core.cljs"]
|
||||
android: ["core.cljs"]
|
||||
common: ["handlers.cljs", "subs.cljs", "db.cljs"]
|
||||
other: [["reagent_dom.cljs","reagent/dom.cljs"], ["reagent_dom_server.cljs","reagent/dom/server.cljs"]]
|
||||
deps: ['[reagent "0.6.0-alpha" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]]'
|
||||
'[re-frame "0.7.0"]'
|
||||
'[prismatic/schema "1.0.4"]']
|
||||
shims: ["cljsjs.react", "cljsjs.react.dom", "cljsjs.react.dom.server"]
|
||||
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.ios.core)'
|
||||
sampleCommand: '(dispatch [:set-greeting "Hello Native World!"])'
|
||||
'om-next':
|
||||
cljsDir: "cljs-om-next"
|
||||
sources:
|
||||
@ -435,7 +448,7 @@ openXcode = (name) ->
|
||||
message
|
||||
|
||||
generateRequireModulesCode = (modules) ->
|
||||
jsCode = "var modules={'react-native': require('react-native')};"
|
||||
jsCode = "var modules={'react-native': require('react-native'), 'react': require('react')};"
|
||||
for m in modules
|
||||
jsCode += "modules['#{m}']=require('#{m}');";
|
||||
jsCode += '\n'
|
||||
|
11
resources/cljs-reagent/reagent_dom.cljs
Normal file
11
resources/cljs-reagent/reagent_dom.cljs
Normal file
@ -0,0 +1,11 @@
|
||||
(ns reagent.dom)
|
||||
;; Shimmed namespace to make reagent 0.6.0 work with react native packager
|
||||
|
||||
(defn render
|
||||
([_ _])
|
||||
([_ _ _]))
|
||||
(defn unmount-component-at-node [_])
|
||||
|
||||
(defn dom-node [_])
|
||||
|
||||
(defn force-update-all [])
|
6
resources/cljs-reagent/reagent_dom_server.cljs
Normal file
6
resources/cljs-reagent/reagent_dom_server.cljs
Normal file
@ -0,0 +1,6 @@
|
||||
(ns reagent.dom.server)
|
||||
;; Shimmed namespace to make reagent 0.6.0 work with react native packager
|
||||
|
||||
(defn render-to-string [_])
|
||||
|
||||
(defn render-to-static-markup [_])
|
33
resources/cljs-reagent6/core.cljs
Normal file
33
resources/cljs-reagent6/core.cljs
Normal file
@ -0,0 +1,33 @@
|
||||
(ns $PROJECT_NAME_HYPHENATED$.$PLATFORM$.core
|
||||
(:require [reagent.core :as r :refer [atom]]
|
||||
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||
[$PROJECT_NAME_HYPHENATED$.handlers]
|
||||
[$PROJECT_NAME_HYPHENATED$.subs]))
|
||||
|
||||
(def react-native (js/require "react-native"))
|
||||
|
||||
(def app-registry (.-AppRegistry react-native))
|
||||
(def text (r/adapt-react-class (.-Text react-native)))
|
||||
(def view (r/adapt-react-class (.-View react-native)))
|
||||
(def image (r/adapt-react-class (.-Image react-native)))
|
||||
(def touchable-highlight (r/adapt-react-class (.-TouchableHighlight react-native)))
|
||||
|
||||
(def logo-img (js/require "./images/cljs.png"))
|
||||
|
||||
(defn alert [title]
|
||||
(.alert (.-Alert react-native) title))
|
||||
|
||||
(defn app-root []
|
||||
(let [greeting (subscribe [:get-greeting])]
|
||||
(fn []
|
||||
[view {:style {:flex-direction "column" :margin 40 :align-items "center"}}
|
||||
[text {:style {:font-size 30 :font-weight "100" :margin-bottom 20 :text-align "center"}} @greeting]
|
||||
[image {:source logo-img
|
||||
:style {:width 80 :height 80 :margin-bottom 30}}]
|
||||
[touchable-highlight {:style {:background-color "#999" :padding 10 :border-radius 5}
|
||||
:on-press #(alert "HELLO!")}
|
||||
[text {:style {:color "white" :text-align "center" :font-weight "bold"}} "press me"]]])))
|
||||
|
||||
(defn init []
|
||||
(dispatch-sync [:initialize-db])
|
||||
(.registerComponent app-registry "$PROJECT_NAME$" #(r/reactify-component app-root)))
|
8
resources/cljs-reagent6/db.cljs
Normal file
8
resources/cljs-reagent6/db.cljs
Normal file
@ -0,0 +1,8 @@
|
||||
(ns $PROJECT_NAME_HYPHENATED$.db
|
||||
(:require [schema.core :as s :include-macros true]))
|
||||
|
||||
;; schema of app-db
|
||||
(def schema {:greeting s/Str})
|
||||
|
||||
;; initial state of app-db
|
||||
(def app-db {:greeting "Hello Clojure in iOS and Android!"})
|
32
resources/cljs-reagent6/handlers.cljs
Normal file
32
resources/cljs-reagent6/handlers.cljs
Normal file
@ -0,0 +1,32 @@
|
||||
(ns $PROJECT_NAME_HYPHENATED$.handlers
|
||||
(:require
|
||||
[re-frame.core :refer [register-handler after]]
|
||||
[schema.core :as s :include-macros true]
|
||||
[$PROJECT_NAME_HYPHENATED$.db :refer [app-db schema]]))
|
||||
|
||||
;; -- Middleware ------------------------------------------------------------
|
||||
;;
|
||||
;; See https://github.com/Day8/re-frame/wiki/Using-Handler-Middleware
|
||||
;;
|
||||
(defn check-and-throw
|
||||
"throw an exception if db doesn't match the schema."
|
||||
[a-schema db]
|
||||
(if-let [problems (s/check a-schema db)]
|
||||
(throw (js/Error. (str "schema check failed: " problems)))))
|
||||
|
||||
(def validate-schema-mw
|
||||
(after (partial check-and-throw schema)))
|
||||
|
||||
;; -- Handlers --------------------------------------------------------------
|
||||
|
||||
(register-handler
|
||||
:initialize-db
|
||||
validate-schema-mw
|
||||
(fn [_ _]
|
||||
app-db))
|
||||
|
||||
(register-handler
|
||||
:set-greeting
|
||||
validate-schema-mw
|
||||
(fn [db [_ value]]
|
||||
(assoc db :greeting value)))
|
17
resources/cljs-reagent6/main_dev.cljs
Normal file
17
resources/cljs-reagent6/main_dev.cljs
Normal file
@ -0,0 +1,17 @@
|
||||
(ns ^:figwheel-no-load env.$PLATFORM$.main
|
||||
(:require [reagent.core :as r]
|
||||
[$PROJECT_NAME_HYPHENATED$.$PLATFORM$.core :as core]
|
||||
[figwheel.client :as figwheel :include-macros true]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
(def cnt (r/atom 0))
|
||||
(defn reloader [] @cnt [core/app-root])
|
||||
(def root-el (r/as-element [reloader]))
|
||||
|
||||
(figwheel/watch-and-reload
|
||||
:websocket-url "ws://$DEV_HOST$:3449/figwheel-ws"
|
||||
:heads-up-display false
|
||||
:jsload-callback #(swap! cnt inc))
|
||||
|
||||
(core/init)
|
6
resources/cljs-reagent6/main_prod.cljs
Normal file
6
resources/cljs-reagent6/main_prod.cljs
Normal file
@ -0,0 +1,6 @@
|
||||
(ns env.$PLATFORM$.main
|
||||
(:require [$PROJECT_NAME_HYPHENATED$.$PLATFORM$.core :as core]))
|
||||
|
||||
(core/init)
|
||||
|
||||
|
11
resources/cljs-reagent6/reagent_dom.cljs
Normal file
11
resources/cljs-reagent6/reagent_dom.cljs
Normal file
@ -0,0 +1,11 @@
|
||||
(ns reagent.dom)
|
||||
;; Shimmed namespace to make reagent 0.6.0 work with react native packager
|
||||
|
||||
(defn render
|
||||
([_ _])
|
||||
([_ _ _]))
|
||||
(defn unmount-component-at-node [_])
|
||||
|
||||
(defn dom-node [_])
|
||||
|
||||
(defn force-update-all [])
|
6
resources/cljs-reagent6/reagent_dom_server.cljs
Normal file
6
resources/cljs-reagent6/reagent_dom_server.cljs
Normal file
@ -0,0 +1,6 @@
|
||||
(ns reagent.dom.server)
|
||||
;; Shimmed namespace to make reagent 0.6.0 work with react native packager
|
||||
|
||||
(defn render-to-string [_])
|
||||
|
||||
(defn render-to-static-markup [_])
|
9
resources/cljs-reagent6/subs.cljs
Normal file
9
resources/cljs-reagent6/subs.cljs
Normal file
@ -0,0 +1,9 @@
|
||||
(ns $PROJECT_NAME_HYPHENATED$.subs
|
||||
(:require-macros [reagent.ratom :refer [reaction]])
|
||||
(:require [re-frame.core :refer [register-sub]]))
|
||||
|
||||
(register-sub
|
||||
:get-greeting
|
||||
(fn [db _]
|
||||
(reaction
|
||||
(get @db :greeting))))
|
Loading…
x
Reference in New Issue
Block a user