generated from PEZ/rn-rf-shadow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhot_reload.cljs
99 lines (91 loc) · 2.63 KB
/
hot_reload.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(ns gurps.setup.hot-reload
(:require
[re-frame.core :as re-frame]
[react-native.core :as rn]
[reagent.core :as reagent]
;; schema.state
; [status-im.setup.schema :as schema]
))
(defonce cnt (reagent/atom 0))
(defonce reload-locked? (atom false))
(defonce reload-interval (atom nil))
(defonce warning? (reagent/atom false))
(defonce visible (reagent/atom false))
(defonce label (reagent/atom ""))
(defn reload
[]
(js/setTimeout #(reset! visible false) 500)
(js/setTimeout #(reset! reload-locked? false) 3000)
(reset! warning? false)
(reset! visible true)
(reset! label "reloading UI")
(re-frame/clear-subscription-cache!)
;; (schema/setup!)
;; (schema.state/clear-errors)
(swap! cnt inc))
(defn before-reload
[done]
(js/console.log "before-reload called")
(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! warning? false)
(reset! visible true))
(defn build-failed
[warnings]
(reset! warning? true)
(reset! label (str "building failed"
(when (seq warnings)
(str "\n" (count warnings) " warnings"))))
(reset! visible true))
(defn build-start
[]
(reset! warning? false)
(reset! label "building")
(reset! visible true))
(defn build-notify
[{:keys [type info]}]
(cond (= :build-start type)
(build-start)
(or (= :build-failure type)
(and (= :build-complete type) (seq (:warnings info))))
(build-failed (:warnings info))
(= :build-complete type)
(build-completed)))
(defn reload-view
[_]
(fn []
(when @visible
[rn/view
{:pointerEvents :none
:style {:position :absolute
:top 0
:left 0
:right 0
:bottom 0
:justify-content :center
:align-items :center}}
[rn/view
{:width 64
:height 64
:background-color "#0000FF30"
:border-radius 32
:justify-content :center
:align-items :center}
[rn/activity-indicator {:animating true}]]
[rn/text {:style {:margin-top 10 :color (if @warning? :red :black)}}
@label]])))