@ea-lab/reactive-json-docs 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/rjbuild/docs/core/element/special/Switch.md +102 -0
- package/public/rjbuild/docs/core/element/special/Switch.yaml +98 -1
- package/public/rjbuild/docs/core/reaction/fetchData.md +36 -0
- package/public/rjbuild/docs/core/reaction/fetchData.yaml +12 -0
- package/public/rjbuild/docs/core/reaction/submitData.md +2 -0
- package/public/rjbuild/docs/core/reaction/submitData.yaml +12 -0
package/package.json
CHANGED
|
@@ -257,4 +257,106 @@ data:
|
|
|
257
257
|
- name: "string2"
|
|
258
258
|
- name: "string3"
|
|
259
259
|
```
|
|
260
|
+
|
|
261
|
+
## Caveats — common pitfalls that fail silently
|
|
262
|
+
|
|
263
|
+
These two patterns *look* correct, type-check, throw no error, and produce
|
|
264
|
+
empty output. They're easy to miss and have cost real debugging time.
|
|
265
|
+
|
|
266
|
+
### Caveat 1 — `content` must be a template reference, not an inline array
|
|
267
|
+
|
|
268
|
+
Switch iterates whatever you put in `content`, but the per-item template
|
|
269
|
+
context (i.e. what `~.field` resolves against) is fetched from the **reactive
|
|
270
|
+
data store** at the iterated path. An inline array literal in `content` is
|
|
271
|
+
never written to the store, so each iteration's `templateData` ends up
|
|
272
|
+
`undefined` and every `~.field` resolves to nothing.
|
|
273
|
+
|
|
274
|
+
```yaml
|
|
275
|
+
# ❌ Silent failure — items render but ~.label is undefined
|
|
276
|
+
renderView:
|
|
277
|
+
- type: Switch
|
|
278
|
+
content:
|
|
279
|
+
- {label: "Home"}
|
|
280
|
+
- {label: "About"}
|
|
281
|
+
singleOption:
|
|
282
|
+
load: navLink
|
|
283
|
+
|
|
284
|
+
templates:
|
|
285
|
+
navLink:
|
|
286
|
+
type: a
|
|
287
|
+
content: ~.label
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```yaml
|
|
291
|
+
# ✅ Works — content points into the store
|
|
292
|
+
data:
|
|
293
|
+
navItems:
|
|
294
|
+
- {label: "Home"}
|
|
295
|
+
- {label: "About"}
|
|
296
|
+
|
|
297
|
+
renderView:
|
|
298
|
+
- type: Switch
|
|
299
|
+
content: ~~.navItems
|
|
300
|
+
singleOption:
|
|
301
|
+
load: navLink
|
|
302
|
+
|
|
303
|
+
templates:
|
|
304
|
+
navLink:
|
|
305
|
+
type: a
|
|
306
|
+
content: ~.label
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Rule of thumb:** `Switch.content` is always a path reference (`~~.foo` for
|
|
310
|
+
global, `~.foo` for local), never a literal. If your iteration data is
|
|
311
|
+
"constant" from a page-data perspective, that's fine — just put it in the
|
|
312
|
+
YAML's `data:` section. It will still be reachable via `~~.foo`.
|
|
313
|
+
|
|
314
|
+
### Caveat 2 — `singleOption` must use `load:`, not an inline template
|
|
315
|
+
|
|
316
|
+
The per-item `TemplateContext` that makes `~.field` resolve against the
|
|
317
|
+
current item is set up by the `load` branch of the `View` engine. Writing
|
|
318
|
+
`singleOption` as an inline `{type: ..., content: ...}` skips that setup —
|
|
319
|
+
the iteration happens, but `~.field` inside the inline template resolves
|
|
320
|
+
against the **outer** context (whatever was active where the Switch sits),
|
|
321
|
+
not the per-item context.
|
|
322
|
+
|
|
323
|
+
```yaml
|
|
324
|
+
# ❌ ~.name resolves against the outer context, not each user
|
|
325
|
+
renderView:
|
|
326
|
+
- type: Switch
|
|
327
|
+
content: ~~.users
|
|
328
|
+
singleOption:
|
|
329
|
+
type: div
|
|
330
|
+
content: ~.name
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
```yaml
|
|
334
|
+
# ✅ Per-item context is correctly pushed
|
|
335
|
+
renderView:
|
|
336
|
+
- type: Switch
|
|
337
|
+
content: ~~.users
|
|
338
|
+
singleOption:
|
|
339
|
+
load: userCard
|
|
340
|
+
|
|
341
|
+
templates:
|
|
342
|
+
userCard:
|
|
343
|
+
type: div
|
|
344
|
+
content: ~.name
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Rule of thumb:** treat `singleOption` and `options.<key>` as
|
|
348
|
+
`{load: <templateName>}` only. If you find yourself writing an inline
|
|
349
|
+
template there, factor it into `templates:` and reference it.
|
|
350
|
+
|
|
351
|
+
### Debugging checklist when an iteration renders empty
|
|
352
|
+
|
|
353
|
+
1. Is `Switch.content` a `~~.path` (not an inline literal)?
|
|
354
|
+
2. Does that path exist in the store? (Defaults in `data:` are merged in
|
|
355
|
+
unless the parent mounts with a `dataOverride` that omits the field.)
|
|
356
|
+
3. Is `singleOption` / `options.<key>` a `{load: <name>}`?
|
|
357
|
+
4. Is each item in the data an object (not a primitive)? Switch silently
|
|
358
|
+
skips non-object entries.
|
|
359
|
+
5. Is the `usePagination` hook available? Switch returns `null` if not —
|
|
360
|
+
normally guaranteed by `ReactiveJsonRoot` auto-merging
|
|
361
|
+
`coreComponentsPlugin`, but worth checking on a stripped-down root.
|
|
260
362
|
|
|
@@ -118,12 +118,109 @@ renderView:
|
|
|
118
118
|
|
|
119
119
|
# ✅ This will work:
|
|
120
120
|
data:
|
|
121
|
-
items:
|
|
121
|
+
items:
|
|
122
122
|
- name: "string1"
|
|
123
123
|
- name: "string2"
|
|
124
124
|
- name: "string3"
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
## Caveats — common pitfalls that fail silently
|
|
128
|
+
|
|
129
|
+
Two patterns *look* correct, throw no error, and produce empty output.
|
|
130
|
+
They've cost real debugging time.
|
|
131
|
+
|
|
132
|
+
### Caveat 1 — `content` must be a template reference, not an inline array
|
|
133
|
+
|
|
134
|
+
Switch iterates whatever you put in `content`, but the per-item
|
|
135
|
+
template context is fetched from the **reactive data store** at the
|
|
136
|
+
iterated path. An inline array literal in `content` is never written
|
|
137
|
+
to the store, so each iteration's `templateData` ends up `undefined`
|
|
138
|
+
and every `~.field` resolves to nothing.
|
|
139
|
+
|
|
140
|
+
```yaml
|
|
141
|
+
# ❌ Silent failure — items render but ~.label is undefined
|
|
142
|
+
renderView:
|
|
143
|
+
- type: Switch
|
|
144
|
+
content:
|
|
145
|
+
- {label: "Home"}
|
|
146
|
+
- {label: "About"}
|
|
147
|
+
singleOption:
|
|
148
|
+
load: navLink
|
|
149
|
+
templates:
|
|
150
|
+
navLink:
|
|
151
|
+
type: a
|
|
152
|
+
content: ~.label
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```yaml
|
|
156
|
+
# ✅ Works — content points into the store
|
|
157
|
+
data:
|
|
158
|
+
navItems:
|
|
159
|
+
- {label: "Home"}
|
|
160
|
+
- {label: "About"}
|
|
161
|
+
renderView:
|
|
162
|
+
- type: Switch
|
|
163
|
+
content: ~~.navItems
|
|
164
|
+
singleOption:
|
|
165
|
+
load: navLink
|
|
166
|
+
templates:
|
|
167
|
+
navLink:
|
|
168
|
+
type: a
|
|
169
|
+
content: ~.label
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Rule of thumb:** `Switch.content` is always a path reference
|
|
173
|
+
(`~~.foo` for global, `~.foo` for local), never a literal. Constant
|
|
174
|
+
iteration data belongs in the YAML's `data:` section.
|
|
175
|
+
|
|
176
|
+
### Caveat 2 — `singleOption` must use `load:`, not an inline template
|
|
177
|
+
|
|
178
|
+
The per-item TemplateContext that makes `~.field` resolve against the
|
|
179
|
+
current item is set up by the `load` branch of the View engine.
|
|
180
|
+
Writing `singleOption` as an inline `{type: ..., content: ...}` skips
|
|
181
|
+
that setup — the iteration happens, but `~.field` resolves against
|
|
182
|
+
the **outer** context, not the per-item context.
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
# ❌ ~.name resolves against the outer context
|
|
186
|
+
renderView:
|
|
187
|
+
- type: Switch
|
|
188
|
+
content: ~~.users
|
|
189
|
+
singleOption:
|
|
190
|
+
type: div
|
|
191
|
+
content: ~.name
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```yaml
|
|
195
|
+
# ✅ Per-item context is correctly pushed
|
|
196
|
+
renderView:
|
|
197
|
+
- type: Switch
|
|
198
|
+
content: ~~.users
|
|
199
|
+
singleOption:
|
|
200
|
+
load: userCard
|
|
201
|
+
templates:
|
|
202
|
+
userCard:
|
|
203
|
+
type: div
|
|
204
|
+
content: ~.name
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Rule of thumb:** treat `singleOption` and `options.<key>` as
|
|
208
|
+
`{load: <templateName>}` only. Factor inline templates into
|
|
209
|
+
`templates:`.
|
|
210
|
+
|
|
211
|
+
### Debugging checklist when an iteration renders empty
|
|
212
|
+
|
|
213
|
+
1. Is `Switch.content` a `~~.path` (not an inline literal)?
|
|
214
|
+
2. Does that path exist in the store? (Defaults in `data:` are merged
|
|
215
|
+
in unless the parent mounts with a `dataOverride` that omits the
|
|
216
|
+
field.)
|
|
217
|
+
3. Is `singleOption` / `options.<key>` a `{load: <name>}`?
|
|
218
|
+
4. Is each item in the data an object (not a primitive)? Switch
|
|
219
|
+
silently skips non-object entries.
|
|
220
|
+
5. Is the `usePagination` hook available? Switch returns `null` if
|
|
221
|
+
not — normally guaranteed by `ReactiveJsonRoot` auto-merging
|
|
222
|
+
`coreComponentsPlugin`.
|
|
223
|
+
|
|
127
224
|
- type: RjBuildDescriber
|
|
128
225
|
title: "Simple usage with `singleOption` (no pagination)"
|
|
129
226
|
description: |
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
## Properties
|
|
11
11
|
- `httpMethod` (string, optional): The HTTP method to use (default: "get"). Supports: get, post, put, patch, delete, etc.
|
|
12
12
|
- `refreshAppOnResponse` (boolean, optional): If true (default), the response will update the application. If false, the response is ignored (webhook mode).
|
|
13
|
+
- `allowConcurrent` (boolean, optional): When true, allows concurrent requests (bypasses the global lock). Default: false. Implicitly true when `requestKey` is set.
|
|
14
|
+
- `requestKey` (string, optional): Identifier used to group requests that should cancel each other. When set, firing a new request with the same key aborts the previous one client-side (via AbortController). Different keys are independent. Bypasses the global lock automatically. See [Concurrency control](#concurrency-control--requestkey) below.
|
|
13
15
|
- `updateOnlyData` (boolean, optional): When true and `refreshAppOnResponse` is true, only updates the data section instead of replacing the entire RjBuild. Preserves templates and renderView. Default: false.
|
|
14
16
|
- `updateDataAtLocation` (string, optional): When `updateOnlyData` is true, specifies where to place the response data using template path syntax (e.g., "~~.userProfile", "~.config.settings"). If not specified, replaces the entire data object.
|
|
15
17
|
- `url` (string, required): The URL to call (must be a static string, dynamic URLs are not supported)
|
|
@@ -54,6 +56,40 @@ The response event provides access to the complete server response through `<rea
|
|
|
54
56
|
|
|
55
57
|
> **⚠️ Important:** When using `updateOnlyData: true`, the server response must contain **data only**, not a complete RjBuild structure. The response should be the raw data object, not wrapped in `{data: {...}, renderView: [...], templates: {...}}`.
|
|
56
58
|
|
|
59
|
+
## Concurrency control — `requestKey`
|
|
60
|
+
|
|
61
|
+
By default, `fetchData` and `submitData` share a **global lock** at the document level: only one HTTP request can be active across the whole app at any time. A second call fired while the first is in flight is **silently dropped**. This is safe for most cases but bites when a user clicks rapidly through buckets in a filter UI, or hits two save buttons quickly — the second request's siblings (e.g. `setData` updating local UI state) still run, but the request itself never goes out, leaving UI and data out of sync.
|
|
62
|
+
|
|
63
|
+
`requestKey` opts the call into per-key cancel-on-new semantics. The library keeps a registry of in-flight requests keyed by `requestKey` and, on each new call:
|
|
64
|
+
|
|
65
|
+
1. Aborts the previous request with the same key (via `AbortController` on the underlying axios call).
|
|
66
|
+
2. Replaces the registry entry with the new request.
|
|
67
|
+
3. Lets the new request proceed.
|
|
68
|
+
|
|
69
|
+
Aborted requests are silently swallowed: their `.catch` doesn't log an error, and their `.finally` skips the `response` event dispatch. The successor will fire its own `response` event normally.
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
# Rapid clicks on bucket A then B share `facet-refresh` — A's request
|
|
73
|
+
# is aborted as soon as B is fired, so only B's response lands in the
|
|
74
|
+
# store. Without requestKey, B would silently no-op (global lock held
|
|
75
|
+
# by A) and the UI would diverge from the data.
|
|
76
|
+
actions:
|
|
77
|
+
- what: setData
|
|
78
|
+
on: click
|
|
79
|
+
path: ~~.selectedFilter
|
|
80
|
+
value: ~.key
|
|
81
|
+
- what: fetchData
|
|
82
|
+
on: click
|
|
83
|
+
requestKey: facet-refresh
|
|
84
|
+
url: ~~.endpoint
|
|
85
|
+
updateOnlyData: true
|
|
86
|
+
updateDataAtLocation: ~~.result
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Different keys are independent: edit modals on multiple rows can each have their own `requestKey: 'save-row-42'` etc. and save simultaneously without interfering.
|
|
90
|
+
|
|
91
|
+
`requestKey` implies `allowConcurrent: true` — the global lock is bypassed automatically when a key is provided, since per-key cancel-on-new already guarantees single-flight within the key.
|
|
92
|
+
|
|
57
93
|
## Examples
|
|
58
94
|
|
|
59
95
|
### Data Loading with GET (Default)
|
|
@@ -26,6 +26,18 @@ renderView:
|
|
|
26
26
|
details:
|
|
27
27
|
type: Markdown
|
|
28
28
|
content: "If true (default), the response will update the application. If false, the response is ignored (webhook mode)"
|
|
29
|
+
- term:
|
|
30
|
+
code: allowConcurrent
|
|
31
|
+
after: "(boolean, optional)"
|
|
32
|
+
details:
|
|
33
|
+
type: Markdown
|
|
34
|
+
content: "When true, allows concurrent requests (bypasses the global lock). Default: false. Implicitly true when `requestKey` is set."
|
|
35
|
+
- term:
|
|
36
|
+
code: requestKey
|
|
37
|
+
after: "(string, optional)"
|
|
38
|
+
details:
|
|
39
|
+
type: Markdown
|
|
40
|
+
content: "Identifier used to group requests that should cancel each other. When set, firing a new request with the same key aborts the previous one client-side (via AbortController). Different keys are independent. Bypasses the global lock automatically."
|
|
29
41
|
- term:
|
|
30
42
|
code: updateDataAtLocation
|
|
31
43
|
after: "(string, optional)"
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
- `httpMethod` (string, optional): The HTTP method to use (default: "post")
|
|
12
12
|
- `data` (object, optional): The data to send. If not specified, data is sent in an object with the structure `{ data: globalDataContext.templateData }`. If `__state` exists in the context, it is automatically added.
|
|
13
13
|
- `refreshAppOnResponse` (boolean, optional): If true (default), reloads the application with the server response. If false, the response is ignored and **no change is made to the application's state or display** (just like `fetchData`).
|
|
14
|
+
- `allowConcurrent` (boolean, optional): When true, allows concurrent requests (bypasses the global lock). Default: false. Implicitly true when `requestKey` is set.
|
|
15
|
+
- `requestKey` (string, optional): Identifier used to group requests that should cancel each other. When set, firing a new submission with the same key aborts the previous one client-side (via AbortController). Different keys are independent. Bypasses the global lock automatically. See the [Concurrency control section in `fetchData`](fetchData.md#concurrency-control--requestkey) — the semantics are identical.
|
|
14
16
|
- `submitSilently` (boolean, optional): If true, doesn't apply visual disabling styles during submission
|
|
15
17
|
- `updateOnlyData` (boolean, optional): When true and `refreshAppOnResponse` is true, only updates the data section instead of replacing the entire RjBuild. Preserves templates and renderView. Default: false.
|
|
16
18
|
- `updateDataAtLocation` (string, optional): When `updateOnlyData` is true, specifies where to place the response data using template path syntax (e.g., "~~.userProfile", "~.config.settings"). If not specified, replaces the entire data object.
|
|
@@ -35,6 +35,18 @@ renderView:
|
|
|
35
35
|
details:
|
|
36
36
|
type: Markdown
|
|
37
37
|
content: "If true (default), reloads the application with the server response. If false, the response is ignored and **no change is made to the application's state or display** (just like `fetchData`)"
|
|
38
|
+
- term:
|
|
39
|
+
code: allowConcurrent
|
|
40
|
+
after: "(boolean, optional)"
|
|
41
|
+
details:
|
|
42
|
+
type: Markdown
|
|
43
|
+
content: "When true, allows concurrent requests (bypasses the global lock). Default: false. Implicitly true when `requestKey` is set."
|
|
44
|
+
- term:
|
|
45
|
+
code: requestKey
|
|
46
|
+
after: "(string, optional)"
|
|
47
|
+
details:
|
|
48
|
+
type: Markdown
|
|
49
|
+
content: "Identifier used to group requests that should cancel each other. When set, firing a new submission with the same key aborts the previous one client-side (via AbortController). Different keys are independent. Bypasses the global lock automatically. See [Concurrency control in `fetchData`](fetchData) — same semantics."
|
|
38
50
|
- term:
|
|
39
51
|
code: submitSilently
|
|
40
52
|
after: "(boolean, optional)"
|