@ea-lab/reactive-json-docs 2.0.1 → 2.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ea-lab/reactive-json-docs",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Complete documentation for Reactive-JSON - Components, examples and LLM-parsable guides",
5
5
  "main": "public/rjbuild/docs/index.yaml",
6
6
  "files": [
@@ -124,6 +124,59 @@ This is useful for adding a "Save Now" button alongside auto-save:
124
124
  trigger: ~~.saveNow
125
125
  ```
126
126
 
127
+ ## Reacting to Sync Events
128
+
129
+ `DataSync` dispatches two custom DOM events that can be caught using `on:` in its `actions` array:
130
+
131
+ | Event | When it fires |
132
+ |---|---|
133
+ | `syncSuccess` | The server returned a 2xx response. |
134
+ | `syncError` | The request failed (any 4xx, 5xx, or network error). |
135
+
136
+ ### Accessing event data
137
+
138
+ Both events expose their payload through the standard event placeholder system:
139
+
140
+ | Placeholder | Description |
141
+ |---|---|
142
+ | `<reactive-json:event-new-value>` | The response body (`event.detail.value`). On success, this is the full server response. On a structured error (see below), this is the error body returned by the server. |
143
+ | `<reactive-json:event>.detail.responseContext.status` | The HTTP status code (number), or `undefined` for pure network errors. |
144
+
145
+ ### Example
146
+
147
+ ```yaml
148
+ - type: DataSync
149
+ path: ~~.userProfile
150
+ mode: onIdle
151
+ idleDelay: 2000
152
+ actions:
153
+ - what: setData
154
+ on: syncSuccess
155
+ path: ~~.lastSync.httpStatus
156
+ value: "<reactive-json:event>.detail.responseContext.status"
157
+ - what: setData
158
+ on: syncSuccess
159
+ path: ~~.lastSync.response
160
+ value: "<reactive-json:event-new-value>"
161
+ - what: setData
162
+ on: syncError
163
+ path: ~~.lastSync.httpStatus
164
+ value: "<reactive-json:event>.detail.responseContext.status"
165
+ - what: setData
166
+ on: syncError
167
+ path: ~~.lastSync.errorBody
168
+ value: "<reactive-json:event-new-value>"
169
+ ```
170
+
171
+ ### Structured vs. unstructured errors
172
+
173
+ When the server responds with a 4xx/5xx and the body contains a `status` field (matching the Syncable Object format), `DataSync` treats it as a **structured error**:
174
+ - The body replaces the local Syncable Object.
175
+ - `syncError` fires with `event.detail.value` set to that body.
176
+ - The retry mechanism is **not** triggered — the server explicitly acknowledged the error.
177
+
178
+ For raw server or network errors (5xx without a structured body, or the browser being offline), `syncError` fires with `event.detail.value` set to `undefined`. In this case the component generates a local `status` object with `{ type: "error", message: "..." }` and may trigger retries according to `maxRetries`.
179
+
127
180
  ## Error Handling and Retries
128
181
 
129
182
  ### Retry behavior
@@ -166,7 +219,7 @@ templates:
166
219
  - type: TextField
167
220
  dataLocation: ~.data.name
168
221
  - type: DataSync
169
- path: ~
222
+ path: "~"
170
223
  mode: onIdle
171
224
  idleDelay: 1500
172
225
 
@@ -198,6 +198,52 @@ renderView:
198
198
  trigger: ~~.saveNow
199
199
  ```
200
200
 
201
+ ## Reacting to Sync Events
202
+
203
+ `DataSync` dispatches two custom DOM events that can be caught using `on:` in its `actions` array:
204
+
205
+ | Event | When it fires |
206
+ |---|---|
207
+ | `syncSuccess` | The server returned a 2xx response. |
208
+ | `syncError` | The request failed (any 4xx, 5xx, or network error). |
209
+
210
+ Both events expose their payload through the standard event placeholder system:
211
+
212
+ | Placeholder | Description |
213
+ |---|---|
214
+ | `<reactive-json:event-new-value>` | The response body (`event.detail.value`). On success, this is the full server response. On a structured error (see below), this is the error body returned by the server. |
215
+ | `<reactive-json:event>.detail.responseContext.status` | The HTTP status code (number), or `undefined` for pure network errors. |
216
+
217
+ ```yaml
218
+ - type: DataSync
219
+ path: ~~.userProfile
220
+ mode: onIdle
221
+ idleDelay: 2000
222
+ actions:
223
+ - what: setData
224
+ on: syncSuccess
225
+ path: ~~.lastSync.httpStatus
226
+ value: "<reactive-json:event>.detail.responseContext.status"
227
+ - what: setData
228
+ on: syncSuccess
229
+ path: ~~.lastSync.response
230
+ value: "<reactive-json:event-new-value>"
231
+ - what: setData
232
+ on: syncError
233
+ path: ~~.lastSync.httpStatus
234
+ value: "<reactive-json:event>.detail.responseContext.status"
235
+ - what: setData
236
+ on: syncError
237
+ path: ~~.lastSync.errorBody
238
+ value: "<reactive-json:event-new-value>"
239
+ ```
240
+
241
+ ### Structured vs. unstructured errors
242
+
243
+ When the server responds with a 4xx/5xx and the body contains a `status` field (matching the Syncable Object format), `DataSync` treats it as a **structured error**: the body replaces the local Syncable Object, `syncError` fires with `event.detail.value` set to that body, and the retry mechanism is not triggered.
244
+
245
+ For raw server or network errors (5xx without a structured body, or the browser being offline), `syncError` fires with `event.detail.value` set to `undefined`. In this case the component generates a local `status` object with `{ type: "error", message: "..." }` and may trigger retries according to `maxRetries`.
246
+
201
247
  ## Error Handling and Retries
202
248
 
203
249
  ### What triggers retries
@@ -241,7 +287,7 @@ renderView:
241
287
  - type: TextField
242
288
  dataLocation: ~.data.name
243
289
  - type: DataSync
244
- path: ~
290
+ path: "~"
245
291
  mode: onIdle
246
292
  idleDelay: 1500
247
293