-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
167 lines (166 loc) · 6.43 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
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!)
:modules $ [] |respo.calcit/ |lilac/ |memof/ |respo-ui.calcit/
:version |0.0.1
:files $ {}
|app.comp.container $ {}
:ns $ quote
ns app.comp.container $ :require (respo-ui.core :as ui)
respo.core :refer $ defcomp defeffect <> >> div button textarea span input pre
respo.comp.space :refer $ =<
app.config :refer $ dev?
respo.util.format :refer $ hsl
memof.alias :refer $ memof-call
:defs $ {}
|comp-container $ quote
defcomp comp-container (store)
let
states $ :states store
cursor $ or (:cursor states) ([])
state $ or (:data states)
{} $ :content "\""
log-plugin $ use-log (>> states :cont) (:content state)
[] (:effect log-plugin)
div
{} $ :style
merge ui/global ui/column $ {} (:padding 8)
div ({})
input $ {}
:value $ :content state
:placeholder "\"Content"
:style $ merge ui/expand ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :content (:value e)
=< 8 nil
button $ {} (:style ui/button) (:inner-text "\"Run")
:on-click $ fn (e d!)
println $ :content state
=< 24 nil
<> $ str "\"Counter: " (:counter store)
=< 8 nil
button $ {} (:style ui/button) (:inner-text "\"Inc counter")
:on-click $ fn (e d!) (d! :inc nil)
=< nil 16
memof-call comp-demo (>> states :a) "\"A" 10
memof-call comp-demo (>> states :a2) "\"A2" 10
memof-call comp-demo (>> states :a3) "\"A3" 10
memof-call comp-demo (>> states :a4) "\"A4" 10
memof-call comp-demo (>> states :a5) "\"A5" 10
:ui log-plugin
|comp-demo $ quote
defcomp comp-demo (states mark level)
let
cursor $ :cursor states
state $ or (:data states)
{} $ :draft "\""
log-plugin $ memof-call use-log (>> states :demo) "\"DEMO"
println "\"Called:" mark
[] (:effect log-plugin)
div
{} $ :style
{}
:border $ str "\"1px solid " (hsl 0 0 90)
:padding 8
input $ {}
:value $ &map:get state :draft
:style ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :draft (-> e :event .-target .-value)
<> $ str "\"This a demo: " mark
pre $ {}
:style $ {}
:background $ hsl 0 0 95
:padding "\"4px 8px"
:inner-text $ .trim (format-cirru-edn state)
; if (> level 10)
comp-demo (>> states level) (str "\"M-" level) (dec level)
:ui log-plugin
|use-plugin $ quote
defn use-plugin (mark)
div
{} $ :style
{} $ :border
str "\"1px solid " $ hsl 0 0 93
<> $ str "\"log ::: " mark
|use-log $ quote
defn use-log (states mark)
let
cursor $ :cursor states
state $ or (:data states)
{} $ :draft "\""
{}
:ui $ div ({})
<> $ str "\"LOG ::: " mark "\" :: " (:draft state)
input $ {}
:value $ :draft state
:style ui/input
:on-input $ fn (e d!)
d! cursor $ assoc state :draft (-> e :event .-target .-value)
:effect $ effect-log mark
|effect-log $ quote
defeffect effect-log (mark) (action el at?) (js/console.log "\"Effect happen:" mark action)
:proc $ quote ()
|app.config $ {}
:ns $ quote (ns app.config)
:defs $ {}
|dev? $ quote (def dev? true)
|site $ quote
def site $ {} (:storage-key "\"workflow")
:proc $ quote ()
|app.main $ {}
:ns $ quote
ns app.main $ :require
respo.core :refer $ render! clear-cache!
app.comp.container :refer $ comp-container
app.updater :refer $ updater
app.schema :as schema
app.config :as config
:defs $ {}
|dispatch! $ quote
defn dispatch! (op op-data)
when
and config/dev? $ not= op :states
println "\"Dispatch:" op $ ; op-data
let
op-id $ generate-id!
op-time $ js/Date.now
reset! *store $ updater @*store op op-data op-id op-time
|*store $ quote (defatom *store schema/store)
|main! $ quote
defn main! () (load-console-formatter!)
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
render-app!
add-watch *store :changes $ fn (store prev) (render-app!)
println "|App started."
|render-app! $ quote
defn render-app! () $ render! mount-target
w-js-log $ comp-container @*store
, dispatch!
|reload! $ quote
defn reload! () (clear-cache!) (remove-watch *store :changes)
add-watch *store :changes $ fn (store prev) (render-app!)
render-app!
|mount-target $ quote
def mount-target $ .querySelector js/document |.app
:proc $ quote ()
|app.schema $ {}
:ns $ quote (ns app.schema)
:defs $ {}
|store $ quote
def store $ {}
:states $ {}
:cursor $ []
:counter 0
:proc $ quote ()
|app.updater $ {}
:ns $ quote
ns app.updater $ :require
respo.cursor :refer $ update-states
:defs $ {}
|updater $ quote
defn updater (store op data op-id op-time)
case op
:states $ update-states store data
:inc $ update store :counter inc
op store
:proc $ quote ()