Improve hot reloading (#16349)

This commit is contained in:
Parvesh Monu 2023-06-22 16:55:09 +05:30 committed by GitHub
parent 1953137068
commit 8a4cba56f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 15 deletions

View File

@ -44,15 +44,16 @@
;; the target files (a.k.a hot reload). When false, you can manually ;; the target files (a.k.a hot reload). When false, you can manually
;; reload by calling `shadow.cljs.devtools.api/watch-compile-all!`. ;; reload by calling `shadow.cljs.devtools.api/watch-compile-all!`.
:devtools {:autobuild #shadow/env ["SHADOW_AUTOBUILD_ENABLED" :default true :as :bool]} :devtools {:autobuild #shadow/env ["SHADOW_AUTOBUILD_ENABLED" :default true :as :bool]}
:dev {:devtools {:after-load status-im2.setup.hot-reload/reload :dev {:devtools {:before-load-async status-im2.setup.hot-reload/before-reload
:build-notify status-im2.setup.hot-reload/build-notify :after-load-async status-im2.setup.hot-reload/reload
:preloads [re-frisk-remote.preload :build-notify status-im2.setup.hot-reload/build-notify
;; In order to use component test helpers in :preloads [re-frisk-remote.preload
;; the REPL we need to preload namespaces ;; In order to use component test helpers in
;; that are not normally required by ;; the REPL we need to preload namespaces
;; production code, such as ;; that are not normally required by
;; @testing-library/react-native. ;; production code, such as
test-helpers.component]} ;; @testing-library/react-native.
test-helpers.component]}
:closure-defines :closure-defines
{status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN" {status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
status-im2.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN" status-im2.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"

View File

@ -3,23 +3,41 @@
[react-native.core :as rn] [react-native.core :as rn]
[reagent.core :as reagent])) [reagent.core :as reagent]))
(def cnt (reagent/atom 0)) (defonce cnt (reagent/atom 0))
(defonce reload-locked? (atom false))
(defonce reload-interval (atom nil))
(defonce warning? (reagent/atom false)) (defonce warning? (reagent/atom false))
(defonce visible (reagent/atom false)) (defonce visible (reagent/atom false))
(defonce timeout (reagent/atom false))
(defonce label (reagent/atom "")) (defonce label (reagent/atom ""))
(defn reload (defn reload
[] []
(when @timeout (js/clearTimeout @timeout)) (js/setTimeout #(reset! visible false) 500)
(reset! timeout (js/setTimeout #(reset! visible false) 500)) (js/setTimeout #(reset! reload-locked? false) 3000)
(reset! warning? false) (reset! warning? false)
(reset! visible true) (reset! visible true)
(reset! label "reloading UI") (reset! label "reloading UI")
(re-frame/clear-subscription-cache!) (re-frame/clear-subscription-cache!)
(swap! cnt inc)) (swap! cnt inc))
(defn build-competed (defn before-reload
[done]
(when @reload-interval (js/clearInterval @reload-interval))
(if @reload-locked?
(reset!
reload-interval
(js/setInterval
(fn []
(when-not @reload-locked?
(js/clearInterval @reload-interval)
(reset! reload-locked? true)
(done)))
500))
(do
(reset! reload-locked? true)
(done))))
(defn build-completed
[] []
(reset! label "reloading code") (reset! label "reloading code")
(reset! warning? false) (reset! warning? false)
@ -47,7 +65,7 @@
(and (= :build-complete type) (seq (:warnings info)))) (and (= :build-complete type) (seq (:warnings info))))
(build-failed (:warnings info)) (build-failed (:warnings info))
(= :build-complete type) (= :build-complete type)
(build-competed))) (build-completed)))
(defn reload-view (defn reload-view
[_] [_]