Merge pull request #410 from status-im/feature/reloadable-js-resources

Reloadable js resources for jail

Former-commit-id: d9240860a78155d35f5b0a37c9d302493735f3d0
This commit is contained in:
Jarrad 2016-11-03 05:05:38 -05:00 committed by GitHub
commit 49fdaf6ccd
17 changed files with 144 additions and 97 deletions

1
.gitignore vendored
View File

@ -59,6 +59,7 @@ figwheel_server.log
# Lein
#
.lein-failures
.lein-repl-history
## Doo
#

View File

@ -1,4 +1,4 @@
(ns ^:figwheel-no-load env.android.main
(ns ^:figwheel-no-load env.android.main
(:require [reagent.core :as r]
[status-im.android.core :as core]
[figwheel.client :as figwheel :include-macros true]))
@ -8,10 +8,14 @@
(def cnt (r/atom 0))
(defn reloader [] @cnt [core/app-root])
(def root-el (r/as-element [reloader]))
(defn callback []
(swap! cnt inc)
(status-im.components.status/init-jail)
(re-frame.core/dispatch [:load-commands!]))
(figwheel/watch-and-reload
:websocket-url "ws://10.0.2.2:3449/figwheel-ws"
:heads-up-display false
:jsload-callback #(swap! cnt inc))
:websocket-url "ws://10.0.3.2:3449/figwheel-ws"
:heads-up-display false
:jsload-callback callback)
(core/init)

View File

@ -2,8 +2,8 @@
(:require [reagent.core :as r]
[status-im.android.core :as core]
[figwheel.client :as figwheel :include-macros true]
[status-im.test.handlers-stubs :refer [init-stubs]]))
;[status-im.test.handlers-stubs :refer [init-stubs]]
))
(enable-console-print!)
(set! js/console.disableYellowBox true)
@ -18,4 +18,4 @@
:jsload-callback #(swap! cnt inc))
(core/init :test)
(init-stubs)
;(init-stubs)

41
env/dev/user.clj vendored
View File

@ -1,5 +1,7 @@
(ns user
(:use [figwheel-sidecar.repl-api :as ra]))
(:use [figwheel-sidecar.repl-api :as ra])
(:require [hawk.core :as hawk]
[clojure.string :as s]))
;; This namespace is loaded automatically by nREPL
;; read project.clj to get build configs
@ -10,17 +12,34 @@
(apply hash-map)
:profiles))
(def cljs-builds (get-in profiles [:dev :cljsbuild :builds]))
(def cljs-builds
(get-in profiles [:dev :cljsbuild :builds]))
(defn start-figwheel
"Start figwheel for one or more builds"
[& build-ids]
(ra/start-figwheel!
{:build-ids build-ids
:all-builds cljs-builds})
(ra/cljs-repl))
"Start figwheel for one or more builds"
[build-ids]
(ra/start-figwheel!
{:figwheel-options {:nrepl-port 7888}
:build-ids build-ids
:all-builds cljs-builds}))
(def start-cljs-repl ra/cljs-repl)
(defn stop-figwheel
"Stops figwheel"
[]
(ra/stop-figwheel!))
"Stops figwheel"
[]
(ra/stop-figwheel!))
(hawk/watch! [{:paths ["resources"]
:handler (fn [ctx e]
(let [path "src/status_im/utils/js_resources.cljs"
js-resourced (slurp path)]
(spit path (str js-resourced " ;;"))
(spit path js-resourced))
ctx)}])
(let [env-build-ids (System/getenv "BUILD_IDS")
build-ids (if env-build-ids
(map keyword (s/split env-build-ids #","))
[:android])]
(start-figwheel build-ids))

View File

@ -164,11 +164,23 @@ function interceptRequire() {
function compileWarningsToYellowBox() {
var log = window.console.log;
var compileWarningRx = /Figwheel: Compile/;
var compileExceptionRx = /Figwheel: Compile Exception/;
var errorInFileRx = /Error on file/;
var isBuffering = false;
var compileExceptionBuffer = "";
window.console.log = function (msg) {
if (compileWarningRx.test(msg)) {
log.apply(window.console, arguments);
if (compileExceptionRx.test(msg)) { // enter buffering mode to get all the messages for exception
isBuffering = true;
compileExceptionBuffer = msg + "\n";
} else if (errorInFileRx.test(msg) && isBuffering) { // exit buffering mode and log buffered messages to YellowBox
isBuffering = false;
console.warn(compileExceptionBuffer + msg);
compileExceptionBuffer = "";
} else if (isBuffering) { //log messages buffering mode
compileExceptionBuffer += msg + "\n";
} else if (compileWarningRx.test(msg)) {
console.warn(msg);
} else {
log.apply(window.console, arguments);
}
};
}
@ -208,7 +220,7 @@ function loadApp(platform, devHost, onLoadCb) {
// seriously React packager? why.
var googreq = goog.require;
googreq('figwheel.connect');
googreq('figwheel.connect.' + platform);
});
});
}
@ -278,4 +290,4 @@ self = {
start: startApp
};
module.exports = self;
module.exports = self;

View File

@ -5,14 +5,14 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.9.0-alpha13"]
[org.clojure/clojurescript "1.9.229"]
[reagent "0.5.1" :exclusions [cljsjs/react]]
[reagent "0.6.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]]
[re-frame "0.7.0"]
[natal-shell "0.3.0"]
[com.andrewmcveigh/cljs-time "0.4.0"]
[tailrecursion/cljs-priority-map "1.2.0"]
[com.taoensso/timbre "4.7.4"]]
:plugins [[lein-cljsbuild "1.1.4"]
[lein-figwheel "0.5.0-2"]]
[lein-figwheel "0.5.8"]]
:clean-targets ["target/" "index.ios.js" "index.android.js"]
:aliases {"prod-build" ^{:doc "Recompile code with prod profile."}
["do" "clean"
@ -20,51 +20,56 @@
["with-profile" "prod" "cljsbuild" "once" "android"]]}
:test-paths ["test/clj"]
:figwheel {:nrepl-port 7888}
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"]
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.8"]
[com.cemerick/piggieback "0.2.1"]
[io.appium/java-client "3.4.1"]]
[io.appium/java-client "3.4.1"]
[hawk "0.2.10"]]
:plugins [[lein-doo "0.1.6"]]
:source-paths ["src" "env/dev"]
:cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/ios/not-used.js"
:main "env.ios.main"
:output-dir "target/ios"
:optimizations :none}}
:android {:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/android/not-used.js"
:main "env.android.main"
:output-dir "target/android"
:optimizations :none}}
:android-test {:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/android/not-used.js"
:main "env.android-test.main"
:output-dir "target/android"
:optimizations :none}}
:test {:source-paths ["src" "test/cljs"]
:compiler
{:main status-im.test.runner
:output-to "target/test/test.js"
:optimizations :none
:target :nodejs}}}}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
:cljsbuild {:builds [{:id :ios
:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/ios/not-used.js"
:main "env.ios.main"
:output-dir "target/ios"
:optimizations :none}}
{:id :android
:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/android/not-used.js"
:main "env.android.main"
:output-dir "target/android"
:optimizations :none}}
{:id :android-test
:source-paths ["src" "env/dev"]
:compiler {:output-to "target/android/not-used.js"
:main "env.android-test.main"
:output-dir "target/android-test"
:optimizations :none}}
{:id :test
:source-paths ["src" "test/cljs"]
:compiler
{:main status-im.test.runner
:output-to "target/test/test.js"
:optimizations :none
:target :nodejs}}]}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]
:timeout 120000}}
:prod {:cljsbuild {:builds [{:id "ios"
:source-paths ["src" "env/prod"]
:compiler {:output-to "index.ios.js"
:main "env.ios.main"
:output-dir "target/ios"
:static-fns true
:compiler {:output-to "index.ios.js"
:main "env.ios.main"
:output-dir "target/ios-prod"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}
{:id "android"
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}
{:id "android"
:source-paths ["src" "env/prod"]
:compiler {:output-to "index.android.js"
:main "env.android.main"
:output-dir "target/android"
:static-fns true
:compiler {:output-to "index.android.js"
:main "env.android.main"
:output-dir "target/android-prod"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}]}}})
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}]}}})

View File

@ -57,7 +57,7 @@ fi
lein deps && re-natal deps && re-natal use-android-device "${device_type}" && re-natal use-figwheel
# open figwheel in new tab
tab "lein figwheel ${cljs_build}"
tab "BUILD_IDS=${cljs_build} lein repl"
# open react-native package in new tab
tab "react-native start"

View File

@ -1,9 +1,4 @@
(ns cljsjs.react)
(when (exists? js/window)
;; cause there is no window.document object in the newest version
;; of React Native, but chance.js requires it
(set! js/window.document #js {})
(set! js/window.React (js/require "react"))
(set! js/ReactNative (js/require "react-native")))

View File

@ -0,0 +1 @@
(ns cljsjs.react.dom)

View File

@ -0,0 +1 @@
(ns cljsjs.react.dom.server)

View File

@ -305,7 +305,9 @@
(let [chat-id (or id current-chat-id)
messages (get-in db [:chats chat-id :messages])
db' (assoc db :current-chat-id chat-id)
commands-loaded? (get-in db [:chats chat-id :commands-loaded])]
commands-loaded? (if js/goog.DEBUG
false
(get-in db [:chats chat-id :commands-loaded]))]
(when (= current-chat-id wallet-chat-id)
(dispatch [:cancel-command]))
(dispatch [:load-requests! chat-id])

View File

@ -53,12 +53,12 @@
:loop? loop?}]
(r/create-class
{:component-did-mount
(when-not @answered? #(request-button-animation-logic context))
(if @answered? #(request-button-animation-logic context) (fn []))
:component-will-unmount
#(reset! loop? false)
:reagent-render
(fn [message-id {command-icon :icon :as command} status-initialized?]
(if command
(when command
[touchable-highlight
{:on-press (when (and (not @answered?) status-initialized?)
#(set-chat-command message-id command))

View File

@ -1,7 +1,6 @@
(ns status-im.chat.views.response
(:require-macros [reagent.ratom :refer [reaction]]
[status-im.utils.views :refer [defview]]
[status-im.utils.slurp :refer [slurp]])
[status-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch]]
[reagent.core :as r]
[status-im.components.react :refer [view
@ -25,7 +24,8 @@
[status-im.i18n :refer [label]]
[status-im.utils.datetime :as dt]
[taoensso.timbre :as log]
[status-im.utils.name :refer [shortened-name]]))
[status-im.utils.name :refer [shortened-name]]
[status-im.utils.js-resources :as js-res]))
(defn drag-icon []
[view st/drag-container
@ -135,7 +135,7 @@
:source {:uri url}
:render-error web-view-error
:java-script-enabled true
:injected-java-script (slurp "resources/webview.js")
:injected-java-script js-res/webview-js
:bounces false
:on-navigation-state-change on-navigation-change}]))

View File

@ -1,5 +1,4 @@
(ns status-im.commands.handlers.loading
(:require-macros [status-im.utils.slurp :refer [slurp]])
(:require [re-frame.core :refer [path after dispatch subscribe trim-v debug]]
[status-im.utils.handlers :as u]
[status-im.utils.utils :refer [http-get show-popup]]
@ -10,13 +9,14 @@
[status-im.commands.utils :refer [reg-handler]]
[status-im.constants :refer [console-chat-id wallet-chat-id]]
[taoensso.timbre :as log]
[status-im.utils.homoglyph :as h]))
[status-im.utils.homoglyph :as h]
[status-im.utils.js-resources :as js-res]))
(def commands-js "commands.js")
(defn load-commands!
[_ [identity]]
(dispatch [::fetch-commands! identity])
[{:keys [current-chat-id]} [identity]]
(dispatch [::fetch-commands! (or identity current-chat-id)])
;; todo uncomment
#_(if-let [{:keys [file]} (commands/get-by-chat-id identity)]
(dispatch [::parse-commands! identity file])
@ -28,13 +28,13 @@
;-let [url (get-in db [:chats identity :dapp-url])]
(cond
(= console-chat-id identity)
(dispatch [::validate-hash identity (slurp "resources/console.js")])
(dispatch [::validate-hash identity js-res/console-js])
(= wallet-chat-id identity)
(dispatch [::validate-hash identity (slurp "resources/wallet.js")])
(dispatch [::validate-hash identity js-res/wallet-js])
:else
(dispatch [::validate-hash identity (slurp "resources/commands.js")])
(dispatch [::validate-hash identity js-res/commands-js])
#_(http-get (s/join "/" [url commands-js])
#(dispatch [::validate-hash identity %])
@ -89,8 +89,8 @@
(let [commands' (filter-forbidden-names id commands)
responses' (filter-forbidden-names id responses)]
(-> db
(update-in [id :commands] merge (mark-as :command commands'))
(update-in [id :responses] merge (mark-as :response responses'))
(assoc-in [id :commands] (mark-as :command commands'))
(assoc-in [id :responses] (mark-as :response responses'))
(assoc-in [id :commands-loaded] true)
(assoc-in [id :autorun] autorun))))

View File

@ -1,6 +1,6 @@
(ns status-im.components.refreshable-text.view
(:require [reagent.core :as r]
[reagent.impl.util :as ru]
[reagent.impl.component :as rc]
[status-im.components.react :refer [view
animated-view
text]]
@ -39,7 +39,7 @@
:value value})
:component-will-update
(fn [component props]
(let [{new-value :value} (ru/extract-props props)
(let [{new-value :value} (rc/extract-props props)
{old-value :value} (r/props component)]
(r/set-state component {:old-value old-value
:value new-value})
@ -64,4 +64,4 @@
:opacity new-value-opacity}}
[text {:style text-style
:font font}
value]]]))})))
value]]]))})))

View File

@ -1,11 +1,12 @@
(ns status-im.components.status
(:require-macros [status-im.utils.slurp :refer [slurp]]
[cljs.core.async.macros :refer [go-loop go]])
(:require-macros
[cljs.core.async.macros :refer [go-loop go]])
(:require [status-im.components.react :as r]
[status-im.utils.types :as t]
[re-frame.core :refer [dispatch]]
[taoensso.timbre :as log]
[cljs.core.async :refer [<! timeout]]))
[cljs.core.async :refer [<! timeout]]
[status-im.utils.js-resources :as js-res]))
;; if StatusModule is not initialized better to store
;; calls and make them only when StatusModule is ready
@ -23,7 +24,7 @@
(swap! calls conj args))
(defn call-module [f]
(log/debug :call-module)
(log/debug :call-module f)
(if @module-initialized?
(f)
(store-call f)))
@ -40,14 +41,12 @@
(reset! loop-started false))
(recur (<! (timeout 500))))))
(def status-js (slurp "resources/status.js"))
(def status
(when (exists? (.-NativeModules r/react-native))
(.-Status (.-NativeModules r/react-native))))
(defn init-jail []
(.initJail status status-js #(log/debug "jail initialized")))
(.initJail status js-res/status-js #(log/debug "jail initialized")))
(when status (call-module init-jail))

View File

@ -0,0 +1,8 @@
(ns ^:figwheel-always status-im.utils.js-resources
(:require-macros [status-im.utils.slurp :refer [slurp]]))
(def commands-js (slurp "resources/commands.js"))
(def console-js (slurp "resources/console.js"))
(def status-js (slurp "resources/status.js"))
(def wallet-js (slurp "resources/wallet.js"))
(def webview-js (slurp "resources/webview.js"))