@@ -29,69 +29,116 @@ In `package.cirru` and run `caps`:
2929DOM syntax
3030
3131``` cirru
32- div
33- {}
34- :class-name "|demo-container"
35- :style $ {} (:color :red)
36- :on-click $ fn (event dispatch!)
37- div $ {}
32+ ns app.demo $ :require
33+ respo.core :refer $ div
34+
35+ defn comp-demo (dispatch!)
36+ div
37+ {}
38+ :class-name "|demo-container"
39+ :style $ {} (:color :red)
40+ :on-click $ fn (event d!)
41+ d! :clicked
42+ div $ {}
43+ ```
44+
45+ More examples adapted from ` compact.cirru ` :
46+
47+ ``` cirru
48+ ns app.demo $ :require
49+ respo.core :refer $ defcomp a <>
50+
51+ defcomp comp-link (href text)
52+ a
53+ {} $ :href href
54+ <> text
55+ ```
56+
57+ ``` cirru
58+ ns app.demo $ :require
59+ respo.core :refer $ list-> div
60+
61+ defn comp-list ()
62+ list-> ({})
63+ [] $ [] :a
64+ div $ {}
3865```
3966
4067Text Node:
4168
4269``` cirru
43- <> content
70+ ns app.demo $ :require
71+ respo.core :refer $ <>
4472
45- ; with styles
46- <> content $ {}
47- :color :red
48- :font-size 14})
73+ defn comp-text (content)
74+ <> content
75+
76+ ; with styles
77+ <> content $ {}
78+ :color :red
79+ :font-size 14
4980```
5081
5182Component definition:
5283
5384``` cirru
54- defcomp comp-container (content)
55- div
56- {}
57- :class-name |demo-container
58- :style $ {} (:color :red)
59- <> content
85+ ns app.demo $ :require
86+ respo.core :refer $ div <>
87+
88+ let
89+ comp-container $ fn (content)
90+ div
91+ {}
92+ :class-name |demo-container
93+ :style $ {} (:color :red)
94+ <> content
6095```
6196
6297App initialization:
6398
6499``` cirru
100+ ns app.demo $ :require
101+ respo.core :refer $ render!
102+
65103; initialize store and update store
66- defatom *store $ {} (:point 0)
67- :states $ {}
68- defn dispatch! (op)
69- reset! *store (updater @*store op)
70-
71- ; TODO
72- defn updater (store op)
73- tag-match op
74- (:TODO a b) TODO
75- _ (do (eprintln "|Unknown op:" op) store)
76-
77- ; render to the DOM
78- render! mount-point (comp-container @*store) dispatch!
104+ let
105+ *store $ atom $ {} (:point 0) (:states {})
106+ updater $ fn (store op)
107+ tag-match op
108+ (:TODO a b) store
109+ _ store
110+ dispatch! $ fn (op)
111+ reset! *store $ updater @*store op
112+ mount-point nil
113+ comp-container $ fn (state) state
114+ dispatch! $ :: :TODO 1 2
115+
116+ ; render to the DOM
117+ defn render-app! ()
118+ render! mount-point (comp-container @*store) dispatch!
79119```
80120
81121Rerender on store changes:
82122
83123``` cirru
84- defn render-app! ()
85- render! mount-point (comp-container @ *store) dispatch!
86-
87- add-watch *store :changes $ fn ()
88- render-app!
124+ let
125+ *store $ atom $ {} (:point 0)
126+ render-app! $ fn () nil
127+ add-watch *store :changes $ fn ()
128+ render-app!
89129```
90130
91131Reset virtual DOM caching during hot code swapping, and rerender:
92132
93133``` cirru
94- defn reload! ()
134+ ns app.demo $ :require
135+ respo.core :refer $ clear-cache!
136+
137+ let
138+ *store $ atom $ {} (:point 0)
139+ render-app! $ fn () nil
140+ add-watch *store :changes $ fn ()
141+ render-app!
95142 remove-watch *store :changes
96143 add-watch *store :changes $ fn ()
97144 render-app!
@@ -102,29 +149,35 @@ defn reload! ()
102149Adding effects to component:
103150
104151``` cirru
105- defeffect effect-a (text) (action parent-element at-place?)
106- println action
107- ; action could be :mount :update :amount
108-
109- when (= :mount action)
110- do nil
111-
112- defcomp comp-a (text)
113- []
114- effect-a text
115- div {}
152+ ns app.demo $ :require
153+ respo.core :refer $ div
154+
155+ let
156+ effect-a $ fn (text)
157+ fn (action parent-element at-place?)
158+ println action
159+ ; action could be :mount :update :amount
160+ when (= :mount action) nil
161+ defn comp-a (text)
162+ []
163+ effect-a text
164+ div {}
116165```
117166
118167Define a hooks plugin based on Calcit Record, better use a pure function:
119168
120169``` cirru
121- defn plugin-x (states options)
122- %::
123- %{} PluginX
124- :render $ fn (self) (nth self 1)
125- :show $ fn (self d! ? text)
126- , :plugin-name
127- div ({}) (<> "|Demo")
170+ ns app.demo $ :require
171+ respo.core :refer $ div <>
172+
173+ let
174+ plugin-x $ fn (states options)
175+ %::
176+ %{} :PluginX
177+ :render $ fn (self) (nth self 1)
178+ :show $ fn (self d! ? text) nil
179+ , :plugin-name
180+ div {} (<> "|Demo")
128181```
129182
130183### License
@@ -188,25 +241,6 @@ Core macros and functions for building applications:
188241| ` realize-ssr! ` | [ docs/apis/realize-ssr\_ .md] ( docs/apis/realize-ssr_.md ) | Server-side rendering |
189242| ` list-> ` | [ docs/apis/list->.md] ( docs/apis/list->.md ) | Create list containers |
190243
191- ### Using with Calcit CLI Tools
192-
193- To explore the codebase using ` cr ` commands:
194-
195- ``` bash
196- # List all namespaces
197- cr query ls-ns
198-
199- # Explore core APIs
200- cr query read-ns respo.core
201- cr query peek-def respo.core defcomp
202- cr query read-def respo.core render!
203-
204- # Search for specific functionality
205- cr query find-symbol render!
206- cr query usages respo.core render!
207-
208- # Check project configuration
209- cr query configs
210- ```
244+ ### Agent Workflows
211245
212- For more CLI tool information, see [ Agents.md] ( ./Agents.md ) .
246+ Agent-oriented CLI workflows (query/check-md automation) are maintained in [ Agents.md] ( ./Agents.md ) .
0 commit comments