-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.cirru
206 lines (205 loc) · 10.2 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
{} (: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/
:entries $ {}
:files $ {}
|app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-container (reel)
let
store $ :store reel
states $ :states store
div
{} $ :style (merge ui/global)
div
{} $ :style
merge ui/center $ {} (:height 320)
div
{} $ :style ui/row-center
<> |Topi $ {} (:font-size 64)
:font-family $ str "|Gill Sans," ui/font-fancy
:font-weight 100
:color $ hsl 240 80 90
div $ {}
:style $ {} (:margin-left -10)
:background-image $ str "|url(http://cdn.tiye.me/logo/topix.png)"
:background-size :cover
:width 160
:height 160
:display :inline-block
:opacity 0.8
:class-name |logo-spin
div
{} $ :style
merge ui/row-center $ {} (:font-size 16)
:color $ hsl 0 0 80
<> "\"Sharing topics over the wire!"
=< 8 nil
a $ {} (:href "\"https://github.com/TopixIM/") (:inner-text "\"TopixIM")
=< nil 32
render-projects projects
=< nil 200
when dev? $ comp-reel (>> states :reel) reel ({})
|projects $ %{} :CodeEntry (:doc |)
:code $ quote
def projects $ []
{} (:title "\"Copyboard") (:about "\"Collaborative copyboard") (:url "\"https://github.com/TopixIM/copyboard") (:demo "\"http://repo.topix.im/copyboard")
{} (:title "\"Timegrass") (:about "\"Another Todolist app") (:url "\"https://github.com/TopixIM/timegrass") (:demo "\"http://timegrass.topix.im")
{} (:title "\"Impatiens") (:about "\"A very tiny chatroom app.") (:url "\"https://github.com/TopixIM/impatiens") (:demo "\"http://impatiens.topix.im")
{} (:title "\"Woodenlist") (:about "\"Personal todolist in realtime") (:url "\"https://github.com/TopixIM/woodenlist") (:demo "\"http://wood.topix.im")
{} (:title "\"Pumila") (:about "\"Personal emotion records") (:url "\"https://github.com/TopixIM/pumila") (:demo "\"http://pumila.topix.im")
{} (:title |Tabletwo) (:about "\"Collabrative markdown drafter") (:url "\"https://github.com/TopixIM/tabletwo") (:demo "\"http://tabletwo.topix.im/")
{} (:title "\"Befunge") (:about "\"Collaborative Befunge playground") (:url "\"https://github.com/TopixIM/befunge") (:demo "\"http://repo.topix.im/befunge")
{} (:title "\"Checklist") (:about "\"Collaborative checklist") (:url "\"https://github.com/TopixIM/checklist") (:demo "\"http://repo.topix.im/checklist")
{} (:title "\"Daily") (:about "\"An app for repeating several tasks everyday") (:url "\"https://github.com/TopixIM/daily") (:demo "\"http://repo.topix.im/daily")
{} (:title |Copycat) (:about "\"Copy/paste toolkits") (:url "\"https://github.com/TopixIM/copycat") (:demo "\"http://repo.topix.im/copycat/")
{} (:title "\"Timedrops") (:about "\"Time records") (:url "\"https://github.com/TopixIM/timedrops") (:demo "\"http://repo.topix.im/timedrops/")
|render-projects $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-projects (items)
list->
{} $ :style
merge ui/row $ {} (:flex-wrap :wrap) (:justify-content :center)
-> items $ map-indexed
fn (idx item)
[] idx $ div
{} $ :style
merge ui/row $ {}
:border $ str "\"1px solid " (hsl 180 80 94)
:padding "|8px 16px"
:margin 20
:width 360
:align-items :center
div
{} $ :style
merge ui/row-center $ {} (:font-size 20) (:font-family ui/font-fancy)
a
{}
:href $ :demo item
:target "\"_self"
:style $ {} (:text-decoration :none)
<> $ :title item
=< 8 nil
a
{}
:href $ :url item
:target "\"_blank"
:style $ {} (:text-decoration :none) (:font-size 12)
<> "\"[git]"
=< 8 nil
<> (:about item)
{} $ :color (hsl 0 0 70)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp >> list-> <> a div button textarea span
[] respo.comp.space :refer $ [] =<
[] reel.comp.reel :refer $ [] comp-reel
[] respo-md.comp.md :refer $ [] comp-md
[] respo.util.list :refer $ [] map-with-idx
[] app.config :refer $ [] dev?
|app.config $ %{} :FileEntry
:defs $ {}
|dev? $ %{} :CodeEntry (:doc |)
:code $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ %{} :CodeEntry (:doc |)
:code $ 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/topix-im/") (:cdn-folder "\"tiye.me:cdn/topix-im") (:title "\"Topix") (:icon "\"http://cdn.tiye.me/logo/topix.png") (:storage-key "\"topix.im") (:upload-folder "\"tiye.me:repo/TopixIM/topix.im/")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.config)
|app.main $ %{} :FileEntry
:defs $ {}
|*reel $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when config/dev? $ println "\"Dispatch:" op
reset! *reel $ reel-updater updater @*reel op
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! ()
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
render-app! render!
add-watch *reel :changes $ fn (r p) (render-app! render!)
listen-devtools! |a dispatch!
js/window.addEventListener |beforeunload persist-storage!
flipped js/setInterval 60000 persist-storage!
let
raw $ js/localStorage.getItem (:storage-key config/site)
when (some? raw)
dispatch! $ :: :hydrate-storage (parse-cirru-edn raw)
println "|App started."
|mount-target $ %{} :CodeEntry (:doc |)
:code $ quote
def mount-target $ js/document.querySelector |.app
|persist-storage! $ %{} :CodeEntry (:doc |)
:code $ quote
defn persist-storage! (? e)
js/localStorage.setItem (:storage-key config/site)
format-cirru-edn $ :store @*reel
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (nil? build-errors)
do (remove-watch *reel :changes) (clear-cache!)
add-watch *reel :changes $ fn (reel prev) (render-app! render!)
reset! *reel $ refresh-reel @*reel schema/store updater
hud! "\"ok~" "\"Ok"
hud! "\"error" build-errors
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! (renderer)
renderer mount-target (comp-container @*reel) dispatch!
|repeat! $ %{} :CodeEntry (:doc |)
:code $ quote
defn repeat! (duration cb)
js/setTimeout
fn () (cb)
repeat! (* 1000 duration) cb
* 1000 duration
:ns $ %{} :CodeEntry (:doc |)
:code $ 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 $ %{} :FileEntry
:defs $ {}
|config $ %{} :CodeEntry (:doc |)
:code $ quote
def config $ {} (:storage |workflow)
|store $ %{} :CodeEntry (:doc |)
:code $ quote
def store $ {}
:states $ {}
:content |
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.schema)
|app.updater $ %{} :FileEntry
:defs $ {}
|updater $ %{} :CodeEntry (:doc |)
:code $ quote
defn updater (store op op-id op-time)
tag-match op
:states cursor s
update-states store cursor s
(:content c) (assoc store :content c)
(:hydrate-storage d) d
_ $ do (eprintln "\"Unkown op:" op) store
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.updater $ :require
[] respo.cursor :refer $ [] update-states