-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.cirru
120 lines (119 loc) · 5.11 KB
/
compact.cirru
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |respo.calcit/ |lilac/ |memof/ |respo-ui.calcit/ |respo-markdown.calcit/ |reel.calcit/ |respo-markdown.calcit/ |respo-feather.calcit/
:entries $ {}
:files $ {}
|app.comp.container $ {}
:defs $ {}
|comp-container $ quote
defcomp comp-container (reel)
let
store $ :store reel
states $ :states store
div
{} $ :style (merge ui/global ui/row)
textarea $ {}
:value $ :content store
:placeholder |Content
:style $ merge ui/flex ui/textarea
{} $ :height 320
:on-input $ fn (e d!)
d! :content $ :value e
=< |8px nil
div
{} $ :style ui/flex
comp-md "|This is some content with `code`"
=< |8px nil
button $ {} (:style ui/button)
:inner-text $ str |run
:on-click $ fn (e d! m!)
println $ :content store
when dev? $ comp-reel (>> states :reel) reel ({})
:ns $ quote
ns app.comp.container $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp >> <> div button textarea span
[] respo.comp.space :refer $ [] =<
[] reel.comp.reel :refer $ [] comp-reel
[] respo-md.comp.md :refer $ [] comp-md
[] app.config :refer $ [] dev?
|app.config $ {}
:defs $ {}
|dev? $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ quote
def site $ {} (:dev-ui "\"http://localhost:8100/main.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main.css") (:cdn-url "\"http://cdn.tiye.me/calcit-workflow/") (:cdn-folder "\"tiye.me:cdn/calcit-workflow") (:title "\"Calcit") (:icon "\"http://cdn.tiye.me/logo/mvc-works.png") (:storage-key "\"workflow") (:upload-folder "\"tiye.me:repo/mvc-works/calcit-workflow/")
:ns $ quote (ns app.config)
|app.main $ {}
:defs $ {}
|*reel $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|dispatch! $ quote
defn dispatch! (op op-data) (; println |Dispatch: op)
reset! *reel $ reel-updater updater @*reel op op-data
|main! $ quote
defn main! ()
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
render-app!
add-watch *reel :changes $ fn (r p) (render-app!)
listen-devtools! |k dispatch!
.addEventListener js/window |beforeunload persist-storage!
repeat! 60 persist-storage!
let
raw $ .getItem js/localStorage (:storage-key config/site)
when (some? raw)
dispatch! :hydrate-storage $ parse-cirru-edn raw
println "|App started."
|mount-target $ quote
def mount-target $ .querySelector js/document |.app
|persist-storage! $ quote
defn persist-storage! (? e)
.setItem js/localStorage (:storage-key config/site)
format-cirru-edn $ :store @*reel
|reload! $ quote
defn reload! () $ if (nil? build-errors)
do (remove-watch *reel :changes) (clear-cache!)
add-watch *reel :changes $ fn (reel prev) (render-app!)
reset! *reel $ refresh-reel @*reel schema/store updater
hud! "\"ok~" "\"Ok"
hud! "\"error" build-errors
|render-app! $ quote
defn render-app! () $ render! mount-target (comp-container @*reel) dispatch!
|repeat! $ quote
defn repeat! (duration cb)
js/setTimeout
fn () (cb)
repeat! (* 1000 duration) cb
* 1000 duration
:ns $ quote
ns app.main $ :require
[] respo.core :refer $ [] render! clear-cache! realize-ssr!
[] app.comp.container :refer $ [] comp-container
[] app.updater :refer $ [] updater
[] app.schema :as schema
[] reel.util :refer $ [] listen-devtools!
[] reel.core :refer $ [] reel-updater refresh-reel
[] reel.schema :as reel-schema
[] app.config :as config
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
|app.schema $ {}
:defs $ {}
|store $ quote
def store $ {}
:states $ {}
:content |
:ns $ quote (ns app.schema)
|app.updater $ {}
:defs $ {}
|updater $ quote
defn updater (store op op-data op-id op-time)
case-default
do (println "\"Unknown op:") op
:states $ update-states store op-data
:content $ assoc store :content op-data
:hydrate-storage op-data
:ns $ quote
ns app.updater $ :require
[] respo.cursor :refer $ [] update-states