@ea-lab/reactive-json-docs 1.0.0 → 1.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 +2 -2
- package/public/rjbuild/docs/advanced-concepts/forward-update.md +80 -7
- package/public/rjbuild/docs/advanced-concepts/forward-update.yaml +81 -11
- package/public/rjbuild/docs/core/action/CustomEventListener.md +150 -0
- package/public/rjbuild/docs/core/action/CustomEventListener.yaml +158 -0
- package/public/rjbuild/docs/core/action/HashChangeListener.md +1 -1
- package/public/rjbuild/docs/core/action/HashChangeListener.yaml +1 -1
- package/public/rjbuild/docs/core/action/MessageListener.md +1 -1
- package/public/rjbuild/docs/core/action/MessageListener.yaml +1 -1
- package/public/rjbuild/docs/core/action/ReactOnEvent.md +3 -3
- package/public/rjbuild/docs/core/action/ReactOnEvent.yaml +3 -3
- package/public/rjbuild/docs/core/action/index.md +2 -1
- package/public/rjbuild/docs/core/action/index.yaml +2 -1
- package/public/rjbuild/docs/core/reaction/fetchData.md +25 -0
- package/public/rjbuild/docs/core/reaction/fetchData.yaml +30 -2
- package/public/rjbuild/docs/core/reaction/submitData.md +28 -0
- package/public/rjbuild/docs/core/reaction/submitData.yaml +32 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ea-lab/reactive-json-docs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.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": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"private": false,
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@craco/craco": "^7.1.0",
|
|
29
|
-
"@ea-lab/reactive-json": "^1.0
|
|
29
|
+
"@ea-lab/reactive-json": "^1.1.0",
|
|
30
30
|
"@ea-lab/reactive-json-chartjs": "^1.0.0",
|
|
31
31
|
"@npmcli/fs": "^4.0.0",
|
|
32
32
|
"@reduxjs/toolkit": "^2.6.1",
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# Forward update
|
|
2
2
|
|
|
3
|
-
Added in **reactive-json@0.0.43**.
|
|
4
|
-
|
|
5
3
|
> Use the special placeholder `<reactive-json:event>` to reference values coming directly from the DOM or the custom event that triggered a reaction.
|
|
6
4
|
|
|
7
5
|
The **Forward update** pattern lets you use the special placeholder `<reactive-json:event>` inside any reaction arguments. It is primarily useful with `setData`, but can be applied to any reaction. Instead of reading a value *after* the global data has been updated, you can forward the fresh value carried by the event itself.
|
|
@@ -19,10 +17,29 @@ value: "<reactive-json:event>.target.checked" # For checkboxes
|
|
|
19
17
|
|
|
20
18
|
### The `<reactive-json:event-new-value>` shortcut
|
|
21
19
|
|
|
22
|
-
`<reactive-json:event-new-value>` returns
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
`<reactive-json:event-new-value>` automatically detects and returns the most relevant value from different types of events. The extraction logic varies based on the event type and the target element.
|
|
21
|
+
|
|
22
|
+
#### Extraction Rules Reference
|
|
23
|
+
|
|
24
|
+
| Event Type | Target Element | Logic | Return Value | Example |
|
|
25
|
+
|------------|----------------|-------|--------------|---------|
|
|
26
|
+
| **CustomEvent** | Any | Returns `event.detail.value` | Any value from custom event payload | `<reactive-json:event-new-value>.preferences.theme` |
|
|
27
|
+
| **DOM Event** | `input[type="checkbox"]` | Returns `event.target.checked` | `true` or `false` | `<reactive-json:event-new-value>` → `true` |
|
|
28
|
+
| **DOM Event** | `input[type="radio"]` | Returns `event.target.value` if checked, otherwise `undefined` | String value or `undefined` | `<reactive-json:event-new-value>` → `"option1"` |
|
|
29
|
+
| **DOM Event** | `input[type="text"]`, `textarea`, `select` | Returns `event.target.value` | String value | `<reactive-json:event-new-value>` → `"user input"` |
|
|
30
|
+
| **DOM Event** | Element with `value` property | Returns `event.target.value` | Any value | `<reactive-json:event-new-value>` → `"42"` |
|
|
31
|
+
| **DOM Event** | Element with `checked` property (fallback) | Returns `event.target.checked` | `true` or `false` | `<reactive-json:event-new-value>` → `false` |
|
|
32
|
+
| **Any Event** | No applicable property | Returns `undefined` | `undefined` | `<reactive-json:event-new-value>` → `undefined` |
|
|
33
|
+
|
|
34
|
+
#### Processing Priority
|
|
35
|
+
For DOM events, the extraction follows this priority order:
|
|
36
|
+
1. **Checkbox**: `event.target.checked` (boolean)
|
|
37
|
+
2. **Radio button**: `event.target.value` only if checked, otherwise `undefined`
|
|
38
|
+
3. **General case**: `event.target.value` (if property exists)
|
|
39
|
+
4. **Fallback**: `event.target.checked` (if property exists)
|
|
40
|
+
5. **Default**: `undefined`
|
|
41
|
+
|
|
42
|
+
For CustomEvent objects (like `response` events from `fetchData`), it directly accesses `event.detail.value` and allows further property access with dot notation.
|
|
26
43
|
|
|
27
44
|
## Good Practice
|
|
28
45
|
|
|
@@ -36,11 +53,31 @@ If no property path is provided (`<reactive-json:event>` alone), nothing is forw
|
|
|
36
53
|
|
|
37
54
|
You can access any nested property (`detail`, `key`, etc.).
|
|
38
55
|
|
|
56
|
+
## Event Types
|
|
57
|
+
|
|
58
|
+
### Standard DOM Events
|
|
59
|
+
The forward update system works with standard DOM events (`change`, `input`, `click`, etc.) from form elements and other HTML components.
|
|
60
|
+
|
|
61
|
+
### Response Event
|
|
62
|
+
You can also use the special `response` event with reactions like `fetchData`. This event is triggered when an HTTP request completes successfully, allowing you to access the response data directly.
|
|
63
|
+
|
|
64
|
+
```yaml
|
|
65
|
+
actions:
|
|
66
|
+
- what: fetchData
|
|
67
|
+
url: "/api/user-profile.json"
|
|
68
|
+
on: click
|
|
69
|
+
- what: setData
|
|
70
|
+
on: response # Triggered when fetchData completes
|
|
71
|
+
path: ~~.userTheme
|
|
72
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
73
|
+
```
|
|
74
|
+
|
|
39
75
|
## Typical Use-cases
|
|
40
76
|
|
|
41
77
|
- Real-time mirroring of form fields
|
|
42
|
-
-
|
|
78
|
+
- "Select all" checkboxes
|
|
43
79
|
- Forward arbitrary values coming from events
|
|
80
|
+
- Process HTTP response data immediately after fetch operations
|
|
44
81
|
|
|
45
82
|
## Examples
|
|
46
83
|
|
|
@@ -90,4 +127,40 @@ renderView:
|
|
|
90
127
|
data:
|
|
91
128
|
primary_text: ""
|
|
92
129
|
secondary_text: ""
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Response Event Processing
|
|
133
|
+
|
|
134
|
+
```yaml
|
|
135
|
+
renderView:
|
|
136
|
+
- type: button
|
|
137
|
+
content: "Load User Profile"
|
|
138
|
+
actions:
|
|
139
|
+
- what: fetchData
|
|
140
|
+
on: click
|
|
141
|
+
url: "/api/user-profile.json"
|
|
142
|
+
updateOnlyData: true
|
|
143
|
+
updateDataAtLocation: ~~.userProfile
|
|
144
|
+
- what: setData
|
|
145
|
+
on: response # Triggered when fetchData completes
|
|
146
|
+
path: ~~.userTheme
|
|
147
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
148
|
+
- what: setData
|
|
149
|
+
on: response
|
|
150
|
+
path: ~~.userName
|
|
151
|
+
value: <reactive-json:event-new-value>.name
|
|
152
|
+
- type: div
|
|
153
|
+
content:
|
|
154
|
+
- "User theme: "
|
|
155
|
+
- type: code
|
|
156
|
+
content: ~~.userTheme
|
|
157
|
+
- type: div
|
|
158
|
+
content:
|
|
159
|
+
- "User name: "
|
|
160
|
+
- type: strong
|
|
161
|
+
content: ~~.userName
|
|
162
|
+
|
|
163
|
+
data:
|
|
164
|
+
userTheme: "not-loaded"
|
|
165
|
+
userName: "not-loaded"
|
|
93
166
|
```
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
renderView:
|
|
2
|
-
# Version badge reusable component
|
|
3
|
-
- type: span
|
|
4
|
-
attributes:
|
|
5
|
-
class: "badge bg-secondary px-2 py-1"
|
|
6
|
-
content: "reactive-json@0.0.43"
|
|
7
|
-
|
|
8
2
|
- type: Markdown
|
|
9
3
|
content: |
|
|
10
4
|
# Forward update
|
|
@@ -27,10 +21,31 @@ renderView:
|
|
|
27
21
|
|
|
28
22
|
- type: Markdown
|
|
29
23
|
content: |
|
|
30
|
-
`<reactive-json:event-new-value>`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
## The `<reactive-json:event-new-value>` shortcut
|
|
25
|
+
|
|
26
|
+
`<reactive-json:event-new-value>` automatically detects and returns the most relevant value from different types of events. The extraction logic varies based on the event type and the target element.
|
|
27
|
+
|
|
28
|
+
### Extraction Rules Reference
|
|
29
|
+
|
|
30
|
+
| Event Type | Target Element | Logic | Return Value | Example |
|
|
31
|
+
|------------|----------------|-------|--------------|---------|
|
|
32
|
+
| **CustomEvent** | Any | Returns `event.detail.value` | Any value from custom event payload | `<reactive-json:event-new-value>.preferences.theme` |
|
|
33
|
+
| **DOM Event** | `input[type="checkbox"]` | Returns `event.target.checked` | `true` or `false` | `<reactive-json:event-new-value>` → `true` |
|
|
34
|
+
| **DOM Event** | `input[type="radio"]` | Returns `event.target.value` if checked, otherwise `undefined` | String value or `undefined` | `<reactive-json:event-new-value>` → `"option1"` |
|
|
35
|
+
| **DOM Event** | `input[type="text"]`, `textarea`, `select` | Returns `event.target.value` | String value | `<reactive-json:event-new-value>` → `"user input"` |
|
|
36
|
+
| **DOM Event** | Element with `value` property | Returns `event.target.value` | Any value | `<reactive-json:event-new-value>` → `"42"` |
|
|
37
|
+
| **DOM Event** | Element with `checked` property (fallback) | Returns `event.target.checked` | `true` or `false` | `<reactive-json:event-new-value>` → `false` |
|
|
38
|
+
| **Any Event** | No applicable property | Returns `undefined` | `undefined` | `<reactive-json:event-new-value>` → `undefined` |
|
|
39
|
+
|
|
40
|
+
### Processing Priority
|
|
41
|
+
For DOM events, the extraction follows this priority order:
|
|
42
|
+
1. **Checkbox**: `event.target.checked` (boolean)
|
|
43
|
+
2. **Radio button**: `event.target.value` only if checked, otherwise `undefined`
|
|
44
|
+
3. **General case**: `event.target.value` (if property exists)
|
|
45
|
+
4. **Fallback**: `event.target.checked` (if property exists)
|
|
46
|
+
5. **Default**: `undefined`
|
|
47
|
+
|
|
48
|
+
For CustomEvent objects (like `response` events from `fetchData`), it directly accesses `event.detail.value` and allows further property access with dot notation.
|
|
34
49
|
|
|
35
50
|
**Good practice**
|
|
36
51
|
- For standard form events (`change`, `input`, etc.), prefer the shortcut `<reactive-json:event-new-value>`.
|
|
@@ -43,10 +58,23 @@ renderView:
|
|
|
43
58
|
|
|
44
59
|
You can access any nested property (`detail`, `key`, etc.).
|
|
45
60
|
|
|
61
|
+
## Event Types
|
|
62
|
+
|
|
63
|
+
### Standard DOM Events
|
|
64
|
+
The forward update system works with standard DOM events (`change`, `input`, `click`, etc.) from form elements and other HTML components.
|
|
65
|
+
|
|
66
|
+
### Response Event
|
|
67
|
+
You can also use the special `response` event with reactions like `fetchData`. This event is triggered when an HTTP request completes successfully, allowing you to access the response data directly.
|
|
68
|
+
|
|
46
69
|
Typical use-cases:
|
|
47
70
|
- Real-time mirroring of form fields
|
|
48
71
|
- "Select all" checkboxes
|
|
49
|
-
- Forward arbitrary values coming from events
|
|
72
|
+
- Forward arbitrary values coming from events
|
|
73
|
+
- Process HTTP response data immediately after fetch operations
|
|
74
|
+
|
|
75
|
+
- type: Markdown
|
|
76
|
+
content: |
|
|
77
|
+
## Examples
|
|
50
78
|
|
|
51
79
|
# --- Interactive example: Synchronized CheckBoxes (use-case "Select all")
|
|
52
80
|
- type: RjBuildDescriber
|
|
@@ -104,6 +132,48 @@ renderView:
|
|
|
104
132
|
primary_text: ""
|
|
105
133
|
secondary_text: ""
|
|
106
134
|
|
|
135
|
+
- type: Markdown
|
|
136
|
+
content: |
|
|
137
|
+
### Response Event Processing
|
|
138
|
+
|
|
139
|
+
This example shows how to use the `response` event to process data returned by an HTTP request. When `fetchData` completes successfully, you can extract specific values from the response and store them in different locations using `<reactive-json:event-new-value>`.
|
|
140
|
+
|
|
141
|
+
- type: SyntaxHighlighter
|
|
142
|
+
language: yaml
|
|
143
|
+
title: "Response Event Processing"
|
|
144
|
+
content: |
|
|
145
|
+
renderView:
|
|
146
|
+
- type: button
|
|
147
|
+
content: "Load User Profile"
|
|
148
|
+
actions:
|
|
149
|
+
- what: fetchData
|
|
150
|
+
on: click
|
|
151
|
+
url: "/api/user-profile.json"
|
|
152
|
+
updateOnlyData: true
|
|
153
|
+
updateDataAtLocation: ~~.userProfile
|
|
154
|
+
- what: setData
|
|
155
|
+
on: response # Triggered when fetchData completes
|
|
156
|
+
path: ~~.userTheme
|
|
157
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
158
|
+
- what: setData
|
|
159
|
+
on: response
|
|
160
|
+
path: ~~.userName
|
|
161
|
+
value: <reactive-json:event-new-value>.name
|
|
162
|
+
- type: div
|
|
163
|
+
content:
|
|
164
|
+
- "User theme: "
|
|
165
|
+
- type: code
|
|
166
|
+
content: ~~.userTheme
|
|
167
|
+
- type: div
|
|
168
|
+
content:
|
|
169
|
+
- "User name: "
|
|
170
|
+
- type: strong
|
|
171
|
+
content: ~~.userName
|
|
172
|
+
|
|
173
|
+
data:
|
|
174
|
+
userTheme: "not-loaded"
|
|
175
|
+
userName: "not-loaded"
|
|
176
|
+
|
|
107
177
|
templates:
|
|
108
178
|
|
|
109
179
|
data: {}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# CustomEventListener
|
|
2
|
+
|
|
3
|
+
Executes a reaction when receiving custom events dispatched on DOM elements. This is an internal action component that is automatically used when you specify custom event names (like `on: "response"`) in your actions.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
CustomEventListener should **not** be used directly in the RjBuild. The Reactive-JSON engine will use it automatically when you specify custom event names (not standard DOM events) in any action. The system automatically adds this component to listen for custom events on the specific element that triggered the action.
|
|
8
|
+
|
|
9
|
+
> **Technical requirement**: The element component must provide an `attributesHolderRef` for the listener to attach its event handler to the DOM element.
|
|
10
|
+
|
|
11
|
+
## Properties
|
|
12
|
+
|
|
13
|
+
When using custom event names in actions, you can specify:
|
|
14
|
+
|
|
15
|
+
- `what` (required): Name of the reaction function to execute (e.g., `setData`, `fetchData`, `submitData`, etc.).
|
|
16
|
+
- `on` (required): Name of the custom event to listen for (e.g., `"response"`, `"customUpdate"`, etc.).
|
|
17
|
+
- All other properties are passed as arguments to the reaction function and support [forward update placeholders](../../../advanced-concepts/forward-update.md).
|
|
18
|
+
|
|
19
|
+
## Behavior
|
|
20
|
+
|
|
21
|
+
When you use a custom event name in an action (like `on: "response"`):
|
|
22
|
+
|
|
23
|
+
1. The system automatically adds a CustomEventListener component
|
|
24
|
+
2. It attaches an event listener directly on the element that triggered the action
|
|
25
|
+
3. When the custom event is dispatched on that element:
|
|
26
|
+
- Receives the event object with its custom data
|
|
27
|
+
- Processes any [event placeholders](../../../advanced-concepts/forward-update.md) in the action properties
|
|
28
|
+
- Executes the reaction function specified in `what`
|
|
29
|
+
|
|
30
|
+
## How Custom Events Are Triggered
|
|
31
|
+
|
|
32
|
+
Custom events are typically triggered by reactions like `fetchData` or `submitData`:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
# fetchData automatically dispatches a "response" event when the request completes
|
|
36
|
+
actions:
|
|
37
|
+
- what: fetchData
|
|
38
|
+
on: click
|
|
39
|
+
url: "/api/data.json"
|
|
40
|
+
# When this completes, it dispatches a "response" event on the same element
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
### Process HTTP response data
|
|
46
|
+
```yaml
|
|
47
|
+
renderView:
|
|
48
|
+
- type: button
|
|
49
|
+
content: "Load Data"
|
|
50
|
+
actions:
|
|
51
|
+
- what: fetchData
|
|
52
|
+
on: click
|
|
53
|
+
url: "/api/user-profile.json"
|
|
54
|
+
updateOnlyData: true
|
|
55
|
+
updateDataAtLocation: ~~.userProfile
|
|
56
|
+
- what: setData
|
|
57
|
+
on: response # CustomEventListener handles this automatically
|
|
58
|
+
path: ~~.userTheme
|
|
59
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
60
|
+
- what: setData
|
|
61
|
+
on: response
|
|
62
|
+
path: ~~.lastUpdateTime
|
|
63
|
+
value: <reactive-json:event-new-value>.metadata.timestamp
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### React to submission completion
|
|
67
|
+
```yaml
|
|
68
|
+
renderView:
|
|
69
|
+
- type: button
|
|
70
|
+
content: "Save Profile"
|
|
71
|
+
actions:
|
|
72
|
+
- what: submitData
|
|
73
|
+
on: click
|
|
74
|
+
url: "/api/save-profile"
|
|
75
|
+
data:
|
|
76
|
+
name: ~~.form.name
|
|
77
|
+
email: ~~.form.email
|
|
78
|
+
- what: setData
|
|
79
|
+
on: response # Triggered when submitData completes
|
|
80
|
+
path: ~~.saveStatus
|
|
81
|
+
value: <reactive-json:event-new-value>.status
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Custom event handling
|
|
85
|
+
```yaml
|
|
86
|
+
renderView:
|
|
87
|
+
- type: div
|
|
88
|
+
content: "Custom event handler"
|
|
89
|
+
actions:
|
|
90
|
+
- what: setData
|
|
91
|
+
on: customUpdate # Any custom event name works
|
|
92
|
+
path: ~~.customData
|
|
93
|
+
value: <reactive-json:event-new-value>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Event Data Access
|
|
97
|
+
|
|
98
|
+
CustomEventListener provides full access to the custom event data through the [forward update system](../../../advanced-concepts/forward-update.md):
|
|
99
|
+
|
|
100
|
+
- `<reactive-json:event-new-value>` - Accesses `event.detail.value` for CustomEvent objects
|
|
101
|
+
- `<reactive-json:event>.detail.someProperty` - Direct access to event details
|
|
102
|
+
- `<reactive-json:event>.data.someValue` - For events with data property
|
|
103
|
+
|
|
104
|
+
## System Integration
|
|
105
|
+
|
|
106
|
+
- **Forward Update System**: Supports all event placeholder patterns for accessing event data
|
|
107
|
+
- **Reaction System**: Executes any available reaction function when events are received
|
|
108
|
+
- **Element-Specific**: Listens on the exact element that triggered the original action
|
|
109
|
+
- **Actions.jsx**: Automatically instantiated when custom event names are detected
|
|
110
|
+
|
|
111
|
+
## Differences from Standard Events
|
|
112
|
+
|
|
113
|
+
| Aspect | Standard DOM Events | Custom Events |
|
|
114
|
+
|--------|-------------------|---------------|
|
|
115
|
+
| **Handler** | ReactOnEvent | CustomEventListener |
|
|
116
|
+
| **Event Names** | `click`, `change`, `submit`, etc. | `response`, `customUpdate`, etc. |
|
|
117
|
+
| **Target** | Element (via React event system) | Element (via DOM addEventListener) |
|
|
118
|
+
| **Event Data** | Standard DOM event properties | Custom data in `event.detail` |
|
|
119
|
+
| **Triggering** | User interactions | Programmatic dispatch |
|
|
120
|
+
|
|
121
|
+
## Built-in Custom Events
|
|
122
|
+
|
|
123
|
+
Some reactions automatically dispatch custom events:
|
|
124
|
+
|
|
125
|
+
- **`response`**: Dispatched by `fetchData` and `submitData` when HTTP requests complete successfully
|
|
126
|
+
- **Custom events**: Can be triggered by `triggerEvent` reaction or external JavaScript
|
|
127
|
+
|
|
128
|
+
## Limitations
|
|
129
|
+
|
|
130
|
+
- Only works with custom event names in actions (not as a standalone element)
|
|
131
|
+
- Requires the element component to provide an `attributesHolderRef` for DOM attachment
|
|
132
|
+
- Listens only on the specific element that triggered the original action
|
|
133
|
+
- Custom events must be dispatched on the correct element to be received
|
|
134
|
+
- Event data structure depends on how the custom event was created
|
|
135
|
+
- Automatic cleanup when the component unmounts
|
|
136
|
+
|
|
137
|
+
## Technical Details
|
|
138
|
+
|
|
139
|
+
- Automatically instantiated by the Actions system when custom event names are used
|
|
140
|
+
- Uses `addEventListener` directly on DOM elements (not React's event system)
|
|
141
|
+
- Supports the full [forward update system](../../../advanced-concepts/forward-update.md) for event data access
|
|
142
|
+
- Properly cleans up event listeners when component unmounts
|
|
143
|
+
- Integrates with the plugin system to execute available reaction functions
|
|
144
|
+
|
|
145
|
+
## Related Components
|
|
146
|
+
|
|
147
|
+
- **[ReactOnEvent](ReactOnEvent.md)**: Handles standard DOM events (`click`, `change`, etc.)
|
|
148
|
+
- **[MessageListener](MessageListener.md)**: Handles `on: "message"` events
|
|
149
|
+
- **[Forward Update System](../../../advanced-concepts/forward-update.md)**: Event data access patterns
|
|
150
|
+
- **[Reactions System](../../getting-started/reactions.md)**: The actual reaction functions that CustomEventListener executes
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# CustomEventListener
|
|
5
|
+
|
|
6
|
+
Executes a reaction when receiving custom events dispatched on DOM elements. This is an internal action component that is automatically used when you specify custom event names (like `on: "response"`) in your actions.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
CustomEventListener should **not** be used directly in the RjBuild. The Reactive-JSON engine will use it automatically when you specify custom event names (not standard DOM events) in any action. The system automatically adds this component to listen for custom events on the specific element that triggered the action.
|
|
11
|
+
|
|
12
|
+
> **Technical requirement**: The element component must provide an `attributesHolderRef` for the listener to attach its event handler to the DOM element.
|
|
13
|
+
|
|
14
|
+
## Properties
|
|
15
|
+
|
|
16
|
+
When using custom event names in actions, you can specify:
|
|
17
|
+
|
|
18
|
+
- type: DefinitionList
|
|
19
|
+
content:
|
|
20
|
+
- term:
|
|
21
|
+
code: what
|
|
22
|
+
after: "(required)"
|
|
23
|
+
details: "Name of the reaction function to execute (e.g., `setData`, `fetchData`, `submitData`, etc.)."
|
|
24
|
+
- term:
|
|
25
|
+
code: on
|
|
26
|
+
after: "(required)"
|
|
27
|
+
details: 'Name of the custom event to listen for (e.g., `"response"`, `"customUpdate"`, etc.).'
|
|
28
|
+
- term: "All other properties"
|
|
29
|
+
details:
|
|
30
|
+
type: Markdown
|
|
31
|
+
content: "Are passed as arguments to the reaction function and support [forward update placeholders](../../../advanced-concepts/forward-update)."
|
|
32
|
+
|
|
33
|
+
- type: Markdown
|
|
34
|
+
content: |
|
|
35
|
+
## Behavior
|
|
36
|
+
|
|
37
|
+
When you use a custom event name in an action (like `on: "response"`):
|
|
38
|
+
|
|
39
|
+
1. The system automatically adds a CustomEventListener component
|
|
40
|
+
2. It attaches an event listener directly on the element that triggered the action
|
|
41
|
+
3. When the custom event is dispatched on that element:
|
|
42
|
+
- Receives the event object with its custom data
|
|
43
|
+
- Processes any [event placeholders](../../../advanced-concepts/forward-update) in the action properties
|
|
44
|
+
- Executes the reaction function specified in `what`
|
|
45
|
+
|
|
46
|
+
## How Custom Events Are Triggered
|
|
47
|
+
|
|
48
|
+
Custom events are typically triggered by reactions like `fetchData` or `submitData`:
|
|
49
|
+
|
|
50
|
+
- type: SyntaxHighlighter
|
|
51
|
+
language: yaml
|
|
52
|
+
content: |
|
|
53
|
+
# fetchData automatically dispatches a "response" event when the request completes
|
|
54
|
+
actions:
|
|
55
|
+
- what: fetchData
|
|
56
|
+
on: click
|
|
57
|
+
url: "/api/data.json"
|
|
58
|
+
# When this completes, it dispatches a "response" event on the same element
|
|
59
|
+
|
|
60
|
+
- type: Markdown
|
|
61
|
+
content: |
|
|
62
|
+
## Event Data Access
|
|
63
|
+
|
|
64
|
+
CustomEventListener provides full access to the custom event data through the [forward update system](../../../advanced-concepts/forward-update):
|
|
65
|
+
|
|
66
|
+
- `<reactive-json:event-new-value>` - Accesses `event.detail.value` for CustomEvent objects
|
|
67
|
+
- `<reactive-json:event>.detail.someProperty` - Direct access to event details
|
|
68
|
+
- `<reactive-json:event>.data.someValue` - For events with data property
|
|
69
|
+
|
|
70
|
+
- type: RjBuildDescriber
|
|
71
|
+
title: "Process HTTP Response Data"
|
|
72
|
+
description:
|
|
73
|
+
type: Markdown
|
|
74
|
+
content: |
|
|
75
|
+
This example shows how CustomEventListener automatically handles the `response` event from `fetchData`. The response data can be extracted and stored in different locations using event placeholders.
|
|
76
|
+
toDescribe:
|
|
77
|
+
renderView:
|
|
78
|
+
- type: button
|
|
79
|
+
content: "Load User Profile"
|
|
80
|
+
actions:
|
|
81
|
+
- what: fetchData
|
|
82
|
+
on: click
|
|
83
|
+
url: "/mockup-api/fetchData/example.json"
|
|
84
|
+
updateOnlyData: true
|
|
85
|
+
updateDataAtLocation: ~~.userProfile
|
|
86
|
+
- what: setData
|
|
87
|
+
on: response # CustomEventListener handles this automatically
|
|
88
|
+
path: ~~.userTheme
|
|
89
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
90
|
+
- what: setData
|
|
91
|
+
on: response
|
|
92
|
+
path: ~~.lastUpdateTime
|
|
93
|
+
value: <reactive-json:event-new-value>.metadata.timestamp
|
|
94
|
+
- type: div
|
|
95
|
+
content:
|
|
96
|
+
- "User Theme: "
|
|
97
|
+
- type: code
|
|
98
|
+
content: ~~.userTheme
|
|
99
|
+
- type: div
|
|
100
|
+
content:
|
|
101
|
+
- "Last Update: "
|
|
102
|
+
- type: code
|
|
103
|
+
content: ~~.lastUpdateTime
|
|
104
|
+
data:
|
|
105
|
+
userTheme: "not-loaded"
|
|
106
|
+
lastUpdateTime: "not-loaded"
|
|
107
|
+
|
|
108
|
+
- type: SyntaxHighlighter
|
|
109
|
+
language: yaml
|
|
110
|
+
title: "Custom Event Handling"
|
|
111
|
+
content: |
|
|
112
|
+
renderView:
|
|
113
|
+
- type: div
|
|
114
|
+
content: "Custom event handler"
|
|
115
|
+
actions:
|
|
116
|
+
- what: setData
|
|
117
|
+
on: customUpdate # Any custom event name works
|
|
118
|
+
path: ~~.customData
|
|
119
|
+
value: <reactive-json:event-new-value>
|
|
120
|
+
|
|
121
|
+
- type: Markdown
|
|
122
|
+
content: |
|
|
123
|
+
## Differences from Standard Events
|
|
124
|
+
|
|
125
|
+
| Aspect | Standard DOM Events | Custom Events |
|
|
126
|
+
|--------|-------------------|---------------|
|
|
127
|
+
| **Handler** | ReactOnEvent | CustomEventListener |
|
|
128
|
+
| **Event Names** | `click`, `change`, `submit`, etc. | `response`, `customUpdate`, etc. |
|
|
129
|
+
| **Target** | Element (via React event system) | Element (via DOM addEventListener) |
|
|
130
|
+
| **Event Data** | Standard DOM event properties | Custom data in `event.detail` |
|
|
131
|
+
| **Triggering** | User interactions | Programmatic dispatch |
|
|
132
|
+
|
|
133
|
+
## Built-in Custom Events
|
|
134
|
+
|
|
135
|
+
Some reactions automatically dispatch custom events:
|
|
136
|
+
|
|
137
|
+
- **`response`**: Dispatched by `fetchData` and `submitData` when HTTP requests complete successfully
|
|
138
|
+
- **Custom events**: Can be triggered by `triggerEvent` reaction or external JavaScript
|
|
139
|
+
|
|
140
|
+
## Limitations
|
|
141
|
+
|
|
142
|
+
- Only works with custom event names in actions (not as a standalone element)
|
|
143
|
+
- Requires the element component to provide an `attributesHolderRef` for DOM attachment
|
|
144
|
+
- Listens only on the specific element that triggered the original action
|
|
145
|
+
- Custom events must be dispatched on the correct element to be received
|
|
146
|
+
- Event data structure depends on how the custom event was created
|
|
147
|
+
- Automatic cleanup when the component unmounts
|
|
148
|
+
|
|
149
|
+
## Related Components
|
|
150
|
+
|
|
151
|
+
- **[ReactOnEvent](ReactOnEvent)**: Handles standard DOM events (`click`, `change`, etc.)
|
|
152
|
+
- **[MessageListener](MessageListener)**: Handles `on: "message"` events
|
|
153
|
+
- **[Forward Update System](../../../advanced-concepts/forward-update)**: Event data access patterns
|
|
154
|
+
- **[Reactions System](../../getting-started/reactions)**: The actual reaction functions that CustomEventListener executes
|
|
155
|
+
|
|
156
|
+
templates:
|
|
157
|
+
|
|
158
|
+
data: {}
|
|
@@ -4,7 +4,7 @@ Listens to hash changes (URL fragment) in the window and executes a reaction fun
|
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
HashChangeListener
|
|
7
|
+
HashChangeListener should **not** be used directly in the RjBuild. The Reactive-JSON engine will use it automatically when you use `on: "hashchange"` in any action. The system automatically adds this component to listen for hash changes globally.
|
|
8
8
|
|
|
9
9
|
## Properties
|
|
10
10
|
|
|
@@ -7,7 +7,7 @@ renderView:
|
|
|
7
7
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
10
|
-
HashChangeListener
|
|
10
|
+
HashChangeListener should **not** be used directly in the RjBuild. The Reactive-JSON engine will use it automatically when you use `on: "hashchange"` in any action. The system automatically adds this component to listen for hash changes globally.
|
|
11
11
|
|
|
12
12
|
## Properties
|
|
13
13
|
|
|
@@ -4,7 +4,7 @@ Executes a reaction when receiving a message via `window.postMessage`. This is a
|
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
MessageListener
|
|
7
|
+
MessageListener should **not** be used directly in the RjBuild. The Reactive-JSON engine will use it automatically when you use `on: "message"` in any action. The system automatically adds this component to listen for messages globally on the window object.
|
|
8
8
|
|
|
9
9
|
## Properties
|
|
10
10
|
|
|
@@ -7,7 +7,7 @@ renderView:
|
|
|
7
7
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
10
|
-
MessageListener
|
|
10
|
+
MessageListener should **not** be used directly in the RjBuild. The Reactive-JSON engine will use it automatically when you use `on: "message"` in any action. The system automatically adds this component to listen for messages globally on the window object.
|
|
11
11
|
|
|
12
12
|
## Properties
|
|
13
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ReactOnEvent
|
|
2
2
|
|
|
3
|
-
ReactOnEvent is an internal action component that is automatically instantiated by the Actions system when reactions with event handlers (`on: "eventName"`) are detected. It should **not** be used directly
|
|
3
|
+
ReactOnEvent is an internal action component that is automatically instantiated by the Actions system when reactions with event handlers (`on: "eventName"`) are detected. It should **not** be used directly in the RjBuild.
|
|
4
4
|
|
|
5
5
|
> **Important**: It should **not** be used directly as an element type. The Reactive-JSON engine will automatically instantiate it when needed.
|
|
6
6
|
|
|
@@ -69,9 +69,9 @@ actions:
|
|
|
69
69
|
|
|
70
70
|
## Important Notes
|
|
71
71
|
|
|
72
|
-
- **Never use `type: ReactOnEvent`** in your
|
|
72
|
+
- **Never use `type: ReactOnEvent`** in your RjBuild - it's an internal component
|
|
73
73
|
- **Use `actions` with `on: "eventName"`** - this is the correct way to handle events
|
|
74
|
-
- **
|
|
74
|
+
- **The Reactive-JSON engine will use ReactOnEvent automatically** when needed
|
|
75
75
|
- **Event propagation is stopped by default** - use `stopPropagation: false` to change this
|
|
76
76
|
|
|
77
77
|
## Related Components
|
|
@@ -5,7 +5,7 @@ renderView:
|
|
|
5
5
|
|
|
6
6
|
ReactOnEvent is an internal action component that is automatically instantiated by the Actions system when reactions with event handlers (`on: "eventName"`) are detected.
|
|
7
7
|
|
|
8
|
-
> **Important**: It should **not** be used directly
|
|
8
|
+
> **Important**: It should **not** be used directly in the RjBuild. The Reactive-JSON engine will automatically instantiate it when needed.
|
|
9
9
|
|
|
10
10
|
## How it Works
|
|
11
11
|
|
|
@@ -81,9 +81,9 @@ renderView:
|
|
|
81
81
|
content: |
|
|
82
82
|
## Important Notes
|
|
83
83
|
|
|
84
|
-
- **Never use `type: ReactOnEvent`** in your
|
|
84
|
+
- **Never use `type: ReactOnEvent`** in your RjBuild - it's an internal component
|
|
85
85
|
- **Use `actions` with `on: "eventName"`** - this is the correct way to handle events
|
|
86
|
-
- **
|
|
86
|
+
- **The Reactive-JSON engine will use ReactOnEvent automatically** when needed
|
|
87
87
|
- **Event propagation is stopped by default** - use `stopPropagation: false` to change this
|
|
88
88
|
|
|
89
89
|
## Related Components
|
|
@@ -30,6 +30,7 @@ when the user requests a [reaction](../../getting-started/reactions.md) on a giv
|
|
|
30
30
|
|
|
31
31
|
As a user, you won't need to work with them directly.
|
|
32
32
|
|
|
33
|
+
- **[CustomEventListener](./CustomEventListener.md)**: Reacts to custom events
|
|
33
34
|
- **[HashChangeListener](./HashChangeListener.md)**: Listens for URL hash changes
|
|
34
35
|
- **[MessageListener](./MessageListener.md)**: Listens for window messages
|
|
35
|
-
- **[ReactOnEvent](./ReactOnEvent.md)**: Reacts to
|
|
36
|
+
- **[ReactOnEvent](./ReactOnEvent.md)**: Reacts to DOM events
|
|
@@ -33,7 +33,8 @@ renderView:
|
|
|
33
33
|
|
|
34
34
|
As a user, you won't need to work with them directly.
|
|
35
35
|
|
|
36
|
+
- **[CustomEventListener](./CustomEventListener)**: Reacts to custom events
|
|
36
37
|
- **[HashChangeListener](./HashChangeListener)**: Listens for URL hash changes
|
|
37
38
|
- **[MessageListener](./MessageListener)**: Listens for window messages
|
|
38
|
-
- **[ReactOnEvent](./ReactOnEvent)**: Reacts to
|
|
39
|
+
- **[ReactOnEvent](./ReactOnEvent)**: Reacts to DOM events
|
|
39
40
|
|
|
@@ -27,6 +27,31 @@
|
|
|
27
27
|
- Without `updateDataAtLocation`: **completely replaces** the entire data object
|
|
28
28
|
- With `updateDataAtLocation`: updates only the specified path in the data
|
|
29
29
|
|
|
30
|
+
## Response Event
|
|
31
|
+
|
|
32
|
+
`fetchData` triggers a special `response` event when the HTTP request completes successfully. This allows you to process the response data immediately using other reactions.
|
|
33
|
+
|
|
34
|
+
You can use the `on: response` trigger with any reaction (like `setData`) to access the response data through the [forward update system](../../../advanced-concepts/forward-update.md):
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
actions:
|
|
38
|
+
- what: fetchData
|
|
39
|
+
on: click
|
|
40
|
+
url: "/api/user-profile.json"
|
|
41
|
+
updateOnlyData: true
|
|
42
|
+
updateDataAtLocation: ~~.userProfile
|
|
43
|
+
- what: setData
|
|
44
|
+
on: response # Triggered when fetchData completes
|
|
45
|
+
path: ~~.userTheme
|
|
46
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
47
|
+
- what: setData
|
|
48
|
+
on: response
|
|
49
|
+
path: ~~.lastFetchTime
|
|
50
|
+
value: <reactive-json:event-new-value>.metadata.timestamp
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The response event provides access to the complete server response through `<reactive-json:event-new-value>`, allowing you to extract specific values and store them in different data locations.
|
|
54
|
+
|
|
30
55
|
> **⚠️ 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: {...}}`.
|
|
31
56
|
|
|
32
57
|
## Examples
|
|
@@ -56,6 +56,34 @@ renderView:
|
|
|
56
56
|
- Errors are only logged to the console
|
|
57
57
|
- The triggering element is visually disabled during the request
|
|
58
58
|
|
|
59
|
+
## Response Event
|
|
60
|
+
|
|
61
|
+
`fetchData` triggers a special `response` event when the HTTP request completes successfully. This allows you to process the response data immediately using other reactions.
|
|
62
|
+
|
|
63
|
+
You can use the `on: response` trigger with any reaction (like `setData`) to access the response data through the [forward update system](../../../advanced-concepts/forward-update):
|
|
64
|
+
|
|
65
|
+
- type: SyntaxHighlighter
|
|
66
|
+
language: yaml
|
|
67
|
+
content: |
|
|
68
|
+
actions:
|
|
69
|
+
- what: fetchData
|
|
70
|
+
on: click
|
|
71
|
+
url: "/api/user-profile.json"
|
|
72
|
+
updateOnlyData: true
|
|
73
|
+
updateDataAtLocation: ~~.userProfile
|
|
74
|
+
- what: setData
|
|
75
|
+
on: response # Triggered when fetchData completes
|
|
76
|
+
path: ~~.userTheme
|
|
77
|
+
value: <reactive-json:event-new-value>.preferences.theme
|
|
78
|
+
- what: setData
|
|
79
|
+
on: response
|
|
80
|
+
path: ~~.lastFetchTime
|
|
81
|
+
value: <reactive-json:event-new-value>.metadata.timestamp
|
|
82
|
+
|
|
83
|
+
- type: Markdown
|
|
84
|
+
content: |
|
|
85
|
+
The response event provides access to the complete server response through `<reactive-json:event-new-value>`, allowing you to extract specific values and store them in different data locations.
|
|
86
|
+
|
|
59
87
|
- type: RjBuildDescriber
|
|
60
88
|
title: Basic Structure (GET - Default)
|
|
61
89
|
description:
|
|
@@ -184,11 +212,11 @@ renderView:
|
|
|
184
212
|
title:
|
|
185
213
|
type: Markdown
|
|
186
214
|
content: |
|
|
187
|
-
Data-Only Update Examples
|
|
215
|
+
Data-Only Update Examples
|
|
188
216
|
description:
|
|
189
217
|
- type: Markdown
|
|
190
218
|
content: |
|
|
191
|
-
Properties `updateOnlyData` and `updateDataAtLocation`
|
|
219
|
+
Properties `updateOnlyData` and `updateDataAtLocation` allow for more precise data management:
|
|
192
220
|
|
|
193
221
|
- `updateOnlyData: true`: Only updates the data section, preserving templates and renderView
|
|
194
222
|
- `updateDataAtLocation`: Specifies exactly where to place the response data
|
|
@@ -29,6 +29,34 @@
|
|
|
29
29
|
- Without `updateDataAtLocation`: **completely replaces** the entire data object
|
|
30
30
|
- With `updateDataAtLocation`: updates only the specified path in the data
|
|
31
31
|
|
|
32
|
+
## Response Event
|
|
33
|
+
|
|
34
|
+
`submitData` triggers a special `response` event when the HTTP submission completes successfully. This allows you to process the response data immediately using other reactions.
|
|
35
|
+
|
|
36
|
+
You can use the `on: response` trigger with any reaction (like `setData`) to access the response data through the [forward update system](../../../advanced-concepts/forward-update.md):
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
actions:
|
|
40
|
+
- what: submitData
|
|
41
|
+
on: click
|
|
42
|
+
url: "/api/user/save"
|
|
43
|
+
data:
|
|
44
|
+
name: ~.form.name
|
|
45
|
+
email: ~.form.email
|
|
46
|
+
updateOnlyData: true
|
|
47
|
+
updateDataAtLocation: ~~.userProfile
|
|
48
|
+
- what: setData
|
|
49
|
+
on: response # Triggered when submitData completes
|
|
50
|
+
path: ~~.lastSaveStatus
|
|
51
|
+
value: <reactive-json:event-new-value>.status
|
|
52
|
+
- what: setData
|
|
53
|
+
on: response
|
|
54
|
+
path: ~~.saveTimestamp
|
|
55
|
+
value: <reactive-json:event-new-value>.metadata.savedAt
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The response event provides access to the complete server response through `<reactive-json:event-new-value>`, allowing you to extract specific values and store them in different data locations independently of the main data update process.
|
|
59
|
+
|
|
32
60
|
> **⚠️ 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: {...}}`.
|
|
33
61
|
|
|
34
62
|
## Submission States & Styling
|
|
@@ -64,6 +64,37 @@ renderView:
|
|
|
64
64
|
- In case of an error, the submission is cancelled and logged to the console
|
|
65
65
|
- Interface elements are visually disabled during submission (unless `submitSilently` is enabled)
|
|
66
66
|
|
|
67
|
+
## Response Event
|
|
68
|
+
|
|
69
|
+
`submitData` triggers a special `response` event when the HTTP submission completes successfully. This allows you to process the response data immediately using other reactions.
|
|
70
|
+
|
|
71
|
+
You can use the `on: response` trigger with any reaction (like `setData`) to access the response data through the [forward update system](../../../advanced-concepts/forward-update):
|
|
72
|
+
|
|
73
|
+
- type: SyntaxHighlighter
|
|
74
|
+
language: yaml
|
|
75
|
+
content: |
|
|
76
|
+
actions:
|
|
77
|
+
- what: submitData
|
|
78
|
+
on: click
|
|
79
|
+
url: "/api/user/save"
|
|
80
|
+
data:
|
|
81
|
+
name: ~.form.name
|
|
82
|
+
email: ~.form.email
|
|
83
|
+
updateOnlyData: true
|
|
84
|
+
updateDataAtLocation: ~~.userProfile
|
|
85
|
+
- what: setData
|
|
86
|
+
on: response # Triggered when submitData completes
|
|
87
|
+
path: ~~.lastSaveStatus
|
|
88
|
+
value: <reactive-json:event-new-value>.status
|
|
89
|
+
- what: setData
|
|
90
|
+
on: response
|
|
91
|
+
path: ~~.saveTimestamp
|
|
92
|
+
value: <reactive-json:event-new-value>.metadata.savedAt
|
|
93
|
+
|
|
94
|
+
- type: Markdown
|
|
95
|
+
content: |
|
|
96
|
+
The response event provides access to the complete server response through `<reactive-json:event-new-value>`, allowing you to extract specific values and store them in different data locations independently of the main data update process.
|
|
97
|
+
|
|
67
98
|
## Submission States & Styling
|
|
68
99
|
The system uses a global locking mechanism to handle submissions:
|
|
69
100
|
- Only one submission can be active at a time for all application roots
|
|
@@ -165,7 +196,7 @@ renderView:
|
|
|
165
196
|
- Save progression state
|
|
166
197
|
- Maintain consistency between client and server
|
|
167
198
|
|
|
168
|
-
## Data-Only Update Examples
|
|
199
|
+
## Data-Only Update Examples
|
|
169
200
|
|
|
170
201
|
The properties `updateOnlyData` and `updateDataAtLocation` work identically for `submitData` and `fetchData`.
|
|
171
202
|
|