@ea-lab/reactive-json-docs 0.3.0 → 0.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 +2 -2
- package/public/rjbuild/docs/advanced-concepts/data-mapping.md +76 -0
- package/public/rjbuild/docs/advanced-concepts/data-mapping.yaml +140 -0
- package/public/rjbuild/docs/advanced-concepts/data-processors.md +373 -0
- package/public/rjbuild/docs/advanced-concepts/data-processors.yaml +309 -0
- package/public/rjbuild/docs/advanced-concepts/index.md +10 -0
- package/public/rjbuild/docs/advanced-concepts/index.yaml +16 -0
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/component-development-guide-llm.md +2 -0
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/component-development.md +1 -1
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/component-development.yaml +1 -1
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/plugin-system.md +2 -0
- package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/plugin-system.yaml +2 -0
- package/public/rjbuild/docs/core/action/Hide.md +1 -1
- package/public/rjbuild/docs/core/action/Hide.yaml +10 -10
- package/public/rjbuild/docs/core/action/ReactOnEvent.md +12 -12
- package/public/rjbuild/docs/core/action/ReactOnEvent.yaml +61 -101
- package/public/rjbuild/docs/core/action/Redirect.md +10 -2
- package/public/rjbuild/docs/core/action/Redirect.yaml +18 -51
- package/public/rjbuild/docs/core/action/VisuallyHide.yaml +10 -12
- package/public/rjbuild/docs/core/action/index.md +19 -204
- package/public/rjbuild/docs/core/action/index.yaml +19 -264
- package/public/rjbuild/docs/core/dataMapping/index.md +31 -0
- package/public/rjbuild/docs/core/dataMapping/index.yaml +24 -0
- package/public/rjbuild/docs/core/dataMapping/simpleMapping.md +131 -0
- package/public/rjbuild/docs/core/dataMapping/simpleMapping.yaml +376 -0
- package/public/rjbuild/docs/core/element/form/DateField.md +1 -1
- package/public/rjbuild/docs/core/element/form/DateField.yaml +4 -4
- package/public/rjbuild/docs/core/element/form/SelectField.yaml +2 -2
- package/public/rjbuild/docs/core/element/special/ReactiveJsonSubroot.md +4 -3
- package/public/rjbuild/docs/core/element/special/ReactiveJsonSubroot.yaml +114 -6
- package/public/rjbuild/docs/core/example/website.yaml +10 -10
- package/public/rjbuild/docs/core/reaction/index.md +17 -229
- package/public/rjbuild/docs/core/reaction/index.yaml +14 -242
- package/public/rjbuild/docs/core/reaction/setData.md +1 -1
- package/public/rjbuild/docs/core/reaction/setData.yaml +1 -1
- package/public/rjbuild/docs/docs-components/index.md +0 -2
- package/public/rjbuild/docs/docs-components/index.yaml +0 -2
- package/public/rjbuild/docs/getting-started/actions.md +294 -0
- package/public/rjbuild/docs/getting-started/actions.yaml +403 -0
- package/public/rjbuild/docs/{getting-started.md → getting-started/index.md} +30 -6
- package/public/rjbuild/docs/{getting-started.yaml → getting-started/index.yaml} +22 -6
- package/public/rjbuild/docs/getting-started/reactions.md +301 -0
- package/public/rjbuild/docs/getting-started/reactions.yaml +300 -0
- package/public/rjbuild/docs/getting-started/rjbuild-structure.md +358 -0
- package/public/rjbuild/docs/getting-started/rjbuild-structure.yaml +421 -0
- package/public/rjbuild/docs/{template.md → getting-started/template-contexts-data-binding.md} +16 -12
- package/public/rjbuild/docs/{template.yaml → getting-started/template-contexts-data-binding.yaml} +28 -14
- package/public/rjbuild/docs/install.yaml +682 -681
- /package/public/rjbuild/docs/{core/reaction → advanced-concepts}/forward-update.md +0 -0
- /package/public/rjbuild/docs/{core/reaction → advanced-concepts}/forward-update.yaml +0 -0
- /package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/index.md +0 -0
- /package/public/rjbuild/docs/{extend → advanced-concepts/plugins}/index.yaml +0 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Reactions System
|
|
2
|
+
|
|
3
|
+
Reactions are a fundamental part of Reactive-JSON's interactivity system. They allow you to respond to user events and perform operations like data updates, network requests, and browser interactions - all through JSON configuration. In the RjBuild, reactions are defined under the `actions` key, just like regular actions, but are distinguished by the presence of the `on` property.
|
|
4
|
+
|
|
5
|
+
Reactions execute in response to user events (click, change, etc.) to modify application state and trigger behaviors. They differ from [actions](./actions.md), which continuously adapt the UI based on the current data state; reactions are event-driven while actions are state-driven.
|
|
6
|
+
|
|
7
|
+
## Basic Syntax
|
|
8
|
+
|
|
9
|
+
Reactions are defined as part of the `actions` array on any element. Each reaction has the following core properties:
|
|
10
|
+
|
|
11
|
+
- `what`: The name of the reaction to execute.
|
|
12
|
+
- `on`: The event that triggers the reaction.
|
|
13
|
+
- `when` (optional): Reactions also support optional conditions to control when the reaction should execute. See the [Actions conditional operators documentation](./actions.md#conditional-operators) for detailed information about available condition types.
|
|
14
|
+
|
|
15
|
+
Beyond these core properties, reactions include reaction-specific properties that vary depending on the reaction type. For example, a `setData` reaction requires `path` and `value` properties, while a `fetchData` reaction needs a `url` property and optional `method` configuration.
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
renderView:
|
|
19
|
+
- type: button
|
|
20
|
+
content: "Save Text"
|
|
21
|
+
actions:
|
|
22
|
+
- what: setData # Reaction type
|
|
23
|
+
on: click # Triggering event
|
|
24
|
+
path: ~.saved_text # Reaction-specific property
|
|
25
|
+
value: ~.user_input # Reaction-specific property
|
|
26
|
+
when: ~.user_input # Optional condition
|
|
27
|
+
isNotEmpty: # Condition value
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Basic Reaction Demonstration
|
|
31
|
+
|
|
32
|
+
This example demonstrates how to set data when a button is clicked.
|
|
33
|
+
|
|
34
|
+
On the *Save Text* button, we define a `setData` reaction that will set the text field value in the `saved_text` data location when the button is clicked, but only if the text field is not empty.
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
renderView:
|
|
38
|
+
- type: TextField
|
|
39
|
+
label: "Enter some text:"
|
|
40
|
+
dataLocation: ~.user_input
|
|
41
|
+
placeholder: "Type something..."
|
|
42
|
+
|
|
43
|
+
- type: button
|
|
44
|
+
content: "Save Text"
|
|
45
|
+
actions:
|
|
46
|
+
- what: setData # Reaction type
|
|
47
|
+
on: click # Triggering event
|
|
48
|
+
path: ~.saved_text # Reaction-specific property
|
|
49
|
+
value: ~.user_input # Reaction-specific property
|
|
50
|
+
when: ~.user_input # Optional condition
|
|
51
|
+
isNotEmpty: # Condition value
|
|
52
|
+
|
|
53
|
+
- type: div
|
|
54
|
+
content: ["Saved text: ", ~.saved_text]
|
|
55
|
+
actions:
|
|
56
|
+
- what: hide # Action (no 'on' property)
|
|
57
|
+
when: ~.saved_text # Condition
|
|
58
|
+
isEmpty:
|
|
59
|
+
|
|
60
|
+
data:
|
|
61
|
+
user_input: ""
|
|
62
|
+
saved_text: ""
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Reaction Types
|
|
66
|
+
|
|
67
|
+
Reactive-JSON provides several built-in reactions:
|
|
68
|
+
|
|
69
|
+
### Data Management
|
|
70
|
+
- **setData**: Sets data at the specified path.
|
|
71
|
+
- **addData**: Adds new data to the specified path.
|
|
72
|
+
- **removeData**: Removes data from the specified path.
|
|
73
|
+
- **moveData**: Moves data from one path to another.
|
|
74
|
+
|
|
75
|
+
### Network Operations
|
|
76
|
+
- **fetchData**: Fetches data from a URL using GET requests.
|
|
77
|
+
- **submitData**: Submits data to a server endpoint using POST/PUT/DELETE.
|
|
78
|
+
|
|
79
|
+
### Browser Operations
|
|
80
|
+
- **setClipboardData**: Copies data to the clipboard.
|
|
81
|
+
- **redirectNow**: Performs an immediate redirect.
|
|
82
|
+
- **triggerEvent**: Triggers a custom event.
|
|
83
|
+
- **postMessage**: Sends a message to another window/frame.
|
|
84
|
+
|
|
85
|
+
For detailed documentation of each reaction, including properties and examples, see their respective documentation pages.
|
|
86
|
+
|
|
87
|
+
## Event Types
|
|
88
|
+
|
|
89
|
+
The `on` property accepts standard browser events. These events are the same as those used in standard web development, and their availability depends on the HTML element type. For example, a `change` event will only work on form elements like `input`, `select`, or `textarea`, while a `click` event works on any element.
|
|
90
|
+
|
|
91
|
+
This example demonstrates the different event types supported by reactions:
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
renderView:
|
|
95
|
+
- type: div
|
|
96
|
+
content: ["Last event type: ", ~.last_event_type]
|
|
97
|
+
attributes:
|
|
98
|
+
style:
|
|
99
|
+
padding: "10px"
|
|
100
|
+
border: "1px solid var(--bs-border-color, #dee2e6)"
|
|
101
|
+
borderRadius: "4px"
|
|
102
|
+
marginBottom: "10px"
|
|
103
|
+
fontWeight: "bold"
|
|
104
|
+
|
|
105
|
+
- type: TextField
|
|
106
|
+
label: "Interactive text field:"
|
|
107
|
+
dataLocation: ~.user_input
|
|
108
|
+
placeholder: "Click, type, or hover..."
|
|
109
|
+
actions:
|
|
110
|
+
- what: setData
|
|
111
|
+
on: click
|
|
112
|
+
path: ~.last_event_type
|
|
113
|
+
value: "click"
|
|
114
|
+
- what: setData
|
|
115
|
+
on: change
|
|
116
|
+
path: ~.last_event_type
|
|
117
|
+
value: "change"
|
|
118
|
+
- what: setData
|
|
119
|
+
on: mouseOver
|
|
120
|
+
path: ~.last_event_type
|
|
121
|
+
value: "mouseOver"
|
|
122
|
+
|
|
123
|
+
data:
|
|
124
|
+
last_event_type: "none"
|
|
125
|
+
user_input: ""
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Common event types:
|
|
129
|
+
- `click`: Mouse click (works on any element).
|
|
130
|
+
- `change`: Form input change (works on form elements only).
|
|
131
|
+
- `mouseOver`: Mouse hover (works on any element).
|
|
132
|
+
- `submit`: Form submission (works on form elements only).
|
|
133
|
+
- `keyDown`/`keyUp`: Keyboard events (works on focusable elements).
|
|
134
|
+
|
|
135
|
+
> **Note**: Event names must respect standard React/DOM event naming conventions (camelCase).
|
|
136
|
+
|
|
137
|
+
## Advanced Features
|
|
138
|
+
|
|
139
|
+
### Conditional Logic
|
|
140
|
+
Reactions support the same conditional operators as actions:
|
|
141
|
+
- `when` + `is`/`isNot`: Value equality checks.
|
|
142
|
+
- `when` + `isEmpty`: Empty value tests.
|
|
143
|
+
- `when` + `contains`/`containsNot`: Content search.
|
|
144
|
+
- `when` + `>`, `<`, `>=`, `<=`: Numeric/date comparisons.
|
|
145
|
+
- `andConditions`/`orConditions`: Complex condition logic.
|
|
146
|
+
|
|
147
|
+
### Event Control
|
|
148
|
+
Use `stopPropagation: true` to:
|
|
149
|
+
1. Prevent event bubbling to parent elements.
|
|
150
|
+
2. Stop execution of subsequent actions for the same event.
|
|
151
|
+
|
|
152
|
+
### Execution Order
|
|
153
|
+
- Multiple reactions on the same event execute in the order they are defined.
|
|
154
|
+
- Reactions with unmet conditions are skipped.
|
|
155
|
+
- Actions (without `on` property) are evaluated separately from reactions.
|
|
156
|
+
|
|
157
|
+
## Technical Details
|
|
158
|
+
|
|
159
|
+
- Reactions are triggered by DOM events.
|
|
160
|
+
- Multiple reactions can be defined for the same event.
|
|
161
|
+
- Reactions are executed in the order they appear in the YAML.
|
|
162
|
+
- Reactions can be chained together by modifying data that other reactions depend on.
|
|
163
|
+
- Conditional reactions only execute when their conditions evaluate to true.
|
|
164
|
+
- The `stopPropagation` property affects both event bubbling and subsequent action execution.
|
|
165
|
+
|
|
166
|
+
## Limitations
|
|
167
|
+
|
|
168
|
+
- Event availability depends on the HTML element type (e.g., `change` only works on form elements).
|
|
169
|
+
- Network operations require proper CORS configuration.
|
|
170
|
+
- Browser operations require appropriate permissions.
|
|
171
|
+
- No built-in error handling beyond console logging for network operations.
|
|
172
|
+
- Only one network request (fetch/submit) can be active at a time.
|
|
173
|
+
- URLs in network operations must be static strings (dynamic URLs not supported).
|
|
174
|
+
|
|
175
|
+
## Best Practices
|
|
176
|
+
|
|
177
|
+
1. **Use descriptive conditions**: Make your conditional logic clear and readable.
|
|
178
|
+
2. **Handle empty states**: Always consider what happens when data is empty or undefined.
|
|
179
|
+
3. **Order matters**: Place more specific conditions before general ones.
|
|
180
|
+
4. **Use stopPropagation wisely**: Only use it when you specifically need to prevent event bubbling or stop action execution.
|
|
181
|
+
5. **Test network operations**: Ensure your API endpoints return the expected format.
|
|
182
|
+
6. **Provide user feedback**: Use visual indicators during loading states.
|
|
183
|
+
|
|
184
|
+
## Complete Examples
|
|
185
|
+
|
|
186
|
+
### Data Input and Submission
|
|
187
|
+
```yaml
|
|
188
|
+
renderView:
|
|
189
|
+
- type: TextField
|
|
190
|
+
label: "Username"
|
|
191
|
+
placeholder: "Enter your username"
|
|
192
|
+
dataLocation: ~.form_data.username
|
|
193
|
+
- type: TextField
|
|
194
|
+
label: "Email"
|
|
195
|
+
placeholder: "Enter your email"
|
|
196
|
+
inputType: "email"
|
|
197
|
+
dataLocation: ~.form_data.email
|
|
198
|
+
- type: button
|
|
199
|
+
content: Submit
|
|
200
|
+
actions:
|
|
201
|
+
- what: submitData
|
|
202
|
+
on: click
|
|
203
|
+
url: "/api/submit"
|
|
204
|
+
data:
|
|
205
|
+
username: ~.form_data.username
|
|
206
|
+
email: ~.form_data.email
|
|
207
|
+
when: ~.form_data.username
|
|
208
|
+
isNotEmpty:
|
|
209
|
+
|
|
210
|
+
data:
|
|
211
|
+
form_data:
|
|
212
|
+
username: ""
|
|
213
|
+
email: ""
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Conditional Reactions Example
|
|
217
|
+
```yaml
|
|
218
|
+
renderView:
|
|
219
|
+
- type: button
|
|
220
|
+
content: "Toggle State"
|
|
221
|
+
actions:
|
|
222
|
+
- what: setData
|
|
223
|
+
on: click
|
|
224
|
+
path: ~.button_state
|
|
225
|
+
value: "on"
|
|
226
|
+
when: ~.button_state
|
|
227
|
+
is: "off"
|
|
228
|
+
stopPropagation: true
|
|
229
|
+
- what: setData
|
|
230
|
+
on: click
|
|
231
|
+
path: ~.button_state
|
|
232
|
+
value: "off"
|
|
233
|
+
when: ~.button_state
|
|
234
|
+
is: "on"
|
|
235
|
+
stopPropagation: true
|
|
236
|
+
- type: div
|
|
237
|
+
content: ["Button state: ", ~.button_state]
|
|
238
|
+
- type: div
|
|
239
|
+
content: "Button has been clicked!"
|
|
240
|
+
actions:
|
|
241
|
+
- what: hide
|
|
242
|
+
when: ~.button_state
|
|
243
|
+
is: "off"
|
|
244
|
+
|
|
245
|
+
data:
|
|
246
|
+
button_state: "off"
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Complex Conditional Logic
|
|
250
|
+
```yaml
|
|
251
|
+
renderView:
|
|
252
|
+
- type: TextField
|
|
253
|
+
label: "Enter a number:"
|
|
254
|
+
dataLocation: ~.user_input
|
|
255
|
+
inputType: "number"
|
|
256
|
+
- type: button
|
|
257
|
+
content: "Process Number"
|
|
258
|
+
actions:
|
|
259
|
+
- what: setData
|
|
260
|
+
on: click
|
|
261
|
+
path: ~.result
|
|
262
|
+
value: "Number is valid and positive!"
|
|
263
|
+
andConditions:
|
|
264
|
+
- when: ~.user_input
|
|
265
|
+
isNotEmpty:
|
|
266
|
+
- when: ~.user_input
|
|
267
|
+
">": 0
|
|
268
|
+
- what: setData
|
|
269
|
+
on: click
|
|
270
|
+
path: ~.result
|
|
271
|
+
value: "Number must be positive!"
|
|
272
|
+
when: ~.user_input
|
|
273
|
+
"<=": 0
|
|
274
|
+
- what: setData
|
|
275
|
+
on: click
|
|
276
|
+
path: ~.result
|
|
277
|
+
value: "Please enter a number!"
|
|
278
|
+
when: ~.user_input
|
|
279
|
+
isEmpty: true
|
|
280
|
+
- type: div
|
|
281
|
+
content: ["Result: ", ~.result]
|
|
282
|
+
actions:
|
|
283
|
+
- what: hide
|
|
284
|
+
when: ~.result
|
|
285
|
+
isEmpty: true
|
|
286
|
+
|
|
287
|
+
data:
|
|
288
|
+
user_input: null
|
|
289
|
+
result: null
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Next Steps
|
|
293
|
+
|
|
294
|
+
Congratulations! You've mastered the fundamentals of Reactive-JSON. You now understand how to structure RjBuilds, use templates, and create interactive applications with actions and reactions.
|
|
295
|
+
|
|
296
|
+
Ready to take your skills further? Explore the **[Advanced Concepts](../advanced-concepts/index.md)** to learn about data mapping, custom plugins, and performance optimization techniques.
|
|
297
|
+
|
|
298
|
+
## Related Documentation
|
|
299
|
+
|
|
300
|
+
- **[Actions System](./actions.md)**: Review state-driven UI adaptation.
|
|
301
|
+
- **[Template System](./template-contexts-data-binding.md)**: Revisit data binding patterns.
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# Reactions System
|
|
5
|
+
|
|
6
|
+
Reactions are a fundamental part of Reactive-JSON's interactivity system. They allow you to respond to user events and perform operations like data updates, network requests, and browser interactions - all through JSON configuration. In the RjBuild, reactions are defined under the `actions` key, just like regular actions, but are distinguished by the presence of the `on` property.
|
|
7
|
+
|
|
8
|
+
Reactions execute in response to user events (click, change, etc.) to modify application state and trigger behaviors. They differ from [actions](./actions), which continuously adapt the UI based on the current data state; reactions are event-driven while actions are state-driven.
|
|
9
|
+
|
|
10
|
+
- type: Markdown
|
|
11
|
+
content: |
|
|
12
|
+
## Basic Syntax
|
|
13
|
+
|
|
14
|
+
Reactions are defined as part of the `actions` array on any element. Each reaction has the following core properties:
|
|
15
|
+
|
|
16
|
+
- type: DefinitionList
|
|
17
|
+
content:
|
|
18
|
+
- term:
|
|
19
|
+
code: what
|
|
20
|
+
details: "The name of the reaction to execute."
|
|
21
|
+
- term:
|
|
22
|
+
code: on
|
|
23
|
+
details: "The event that triggers the reaction."
|
|
24
|
+
- term:
|
|
25
|
+
code: when
|
|
26
|
+
after: " (optional)"
|
|
27
|
+
details:
|
|
28
|
+
type: Markdown
|
|
29
|
+
content: "Reactions also support optional conditions to control when the reaction should execute. See the [Actions conditional operators documentation](./actions#conditional-operators) for detailed information about available condition types."
|
|
30
|
+
|
|
31
|
+
- type: Markdown
|
|
32
|
+
content: |
|
|
33
|
+
Beyond these core properties, reactions include reaction-specific properties that vary depending on the reaction type. For example, a `setData` reaction requires `path` and `value` properties, while a `fetchData` reaction needs a `url` property and optional `method` configuration.
|
|
34
|
+
|
|
35
|
+
Reactions also support optional conditions using the same conditional system as actions. This allows you to create sophisticated event-driven behavior that only executes when specific data conditions are met.
|
|
36
|
+
|
|
37
|
+
- type: TabbedSerializer
|
|
38
|
+
yamlSerializedContent: |
|
|
39
|
+
renderView:
|
|
40
|
+
- type: button
|
|
41
|
+
content: "Save Text"
|
|
42
|
+
actions:
|
|
43
|
+
- what: setData # Reaction type
|
|
44
|
+
on: click # Triggering event
|
|
45
|
+
path: ~.saved_text # Reaction-specific property
|
|
46
|
+
value: ~.user_input # Reaction-specific property
|
|
47
|
+
when: ~.user_input # Optional condition
|
|
48
|
+
isNotEmpty: # Condition value
|
|
49
|
+
|
|
50
|
+
- type: RjBuildDescriber
|
|
51
|
+
title: "Basic Reaction Demonstration"
|
|
52
|
+
description:
|
|
53
|
+
- type: Markdown
|
|
54
|
+
content: |
|
|
55
|
+
This example demonstrates how to set data when a button is clicked.
|
|
56
|
+
|
|
57
|
+
On the *Save Text* button, we define a `setData` reaction that will set the text field value
|
|
58
|
+
in the `saved_text` data location when the button is clicked, but only if the text field is not empty.
|
|
59
|
+
|
|
60
|
+
toDescribe:
|
|
61
|
+
renderView:
|
|
62
|
+
- type: TextField
|
|
63
|
+
label: "Enter some text:"
|
|
64
|
+
dataLocation: ~.user_input
|
|
65
|
+
placeholder: "Type something..."
|
|
66
|
+
|
|
67
|
+
- type: button
|
|
68
|
+
content: "Save Text"
|
|
69
|
+
actions:
|
|
70
|
+
- what: setData # Reaction type
|
|
71
|
+
on: click # Triggering event
|
|
72
|
+
path: ~.saved_text # Reaction-specific property
|
|
73
|
+
value: ~.user_input # Reaction-specific property
|
|
74
|
+
when: ~.user_input # Optional condition
|
|
75
|
+
isNotEmpty: # Condition value
|
|
76
|
+
|
|
77
|
+
- type: div
|
|
78
|
+
content: ["Saved text: ", ~.saved_text]
|
|
79
|
+
actions:
|
|
80
|
+
- what: hide # Action (no 'on' property)
|
|
81
|
+
when: ~.saved_text # Condition
|
|
82
|
+
isEmpty:
|
|
83
|
+
|
|
84
|
+
data:
|
|
85
|
+
user_input: ""
|
|
86
|
+
saved_text: ""
|
|
87
|
+
|
|
88
|
+
- type: Markdown
|
|
89
|
+
content: |
|
|
90
|
+
## Reaction Types
|
|
91
|
+
|
|
92
|
+
Reactive-JSON provides several built-in reactions:
|
|
93
|
+
|
|
94
|
+
### Data Management
|
|
95
|
+
- **[setData](../core/reaction/setData)**: Sets data at the specified path.
|
|
96
|
+
- **[addData](../core/reaction/addData)**: Adds new data to the specified path.
|
|
97
|
+
- **[removeData](../core/reaction/removeData)**: Removes data from the specified path.
|
|
98
|
+
- **[moveData](../core/reaction/moveData)**: Moves data from one path to another.
|
|
99
|
+
|
|
100
|
+
### Network Operations
|
|
101
|
+
- **[fetchData](../core/reaction/fetchData)**: Fetches data from a URL using GET requests.
|
|
102
|
+
- **[submitData](../core/reaction/submitData)**: Submits data to a server endpoint using POST/PUT/DELETE.
|
|
103
|
+
|
|
104
|
+
### Browser Operations
|
|
105
|
+
- **[setClipboardData](../core/reaction/setClipboardData)**: Copies data to the clipboard.
|
|
106
|
+
- **[redirectNow](../core/reaction/redirectNow)**: Performs an immediate redirect.
|
|
107
|
+
- **[triggerEvent](../core/reaction/triggerEvent)**: Triggers a custom event.
|
|
108
|
+
- **[postMessage](../core/reaction/postMessage)**: Sends a message to another window/frame.
|
|
109
|
+
|
|
110
|
+
For detailed documentation of each reaction, including properties and examples, see their respective documentation pages.
|
|
111
|
+
|
|
112
|
+
- type: RjBuildDescriber
|
|
113
|
+
title: "Event Types"
|
|
114
|
+
description:
|
|
115
|
+
- type: Markdown
|
|
116
|
+
content: |
|
|
117
|
+
This example demonstrates the different event types supported by reactions.
|
|
118
|
+
|
|
119
|
+
Try interacting with the text field below to see which events are triggered:
|
|
120
|
+
- Type text to trigger `change` events
|
|
121
|
+
- Click on the field to trigger `click` events
|
|
122
|
+
- Hover over the field to trigger `mouseOver` events
|
|
123
|
+
|
|
124
|
+
toDescribe:
|
|
125
|
+
renderView:
|
|
126
|
+
- type: div
|
|
127
|
+
content: ["Last event type: ", ~.last_event_type]
|
|
128
|
+
attributes:
|
|
129
|
+
style:
|
|
130
|
+
padding: "10px"
|
|
131
|
+
border: "1px solid var(--bs-border-color, #dee2e6)"
|
|
132
|
+
borderRadius: "4px"
|
|
133
|
+
marginBottom: "10px"
|
|
134
|
+
fontWeight: "bold"
|
|
135
|
+
|
|
136
|
+
- type: TextField
|
|
137
|
+
label: "Interactive text field:"
|
|
138
|
+
dataLocation: ~.user_input
|
|
139
|
+
placeholder: "Click, type, or hover..."
|
|
140
|
+
actions:
|
|
141
|
+
- what: setData
|
|
142
|
+
on: click
|
|
143
|
+
path: ~.last_event_type
|
|
144
|
+
value: "click"
|
|
145
|
+
- what: setData
|
|
146
|
+
on: change
|
|
147
|
+
path: ~.last_event_type
|
|
148
|
+
value: "change"
|
|
149
|
+
- what: setData
|
|
150
|
+
on: mouseOver
|
|
151
|
+
path: ~.last_event_type
|
|
152
|
+
value: "mouseOver"
|
|
153
|
+
|
|
154
|
+
data:
|
|
155
|
+
last_event_type: "none"
|
|
156
|
+
user_input: ""
|
|
157
|
+
|
|
158
|
+
- type: Markdown
|
|
159
|
+
content: |
|
|
160
|
+
Common event types:
|
|
161
|
+
- `click`: Mouse click (works on any element).
|
|
162
|
+
- `change`: Form input change (works on form elements only).
|
|
163
|
+
- `mouseOver`: Mouse hover (works on any element).
|
|
164
|
+
- `submit`: Form submission (works on form elements only).
|
|
165
|
+
- `keyDown`/`keyUp`: Keyboard events (works on focusable elements).
|
|
166
|
+
|
|
167
|
+
> **Note**: Event names must respect standard React/DOM event naming conventions (camelCase).
|
|
168
|
+
|
|
169
|
+
- type: RjBuildDescriber
|
|
170
|
+
title: "Data Management Example"
|
|
171
|
+
description:
|
|
172
|
+
- type: Markdown
|
|
173
|
+
content: |
|
|
174
|
+
This example demonstrates the core data management reactions: setData, addData, and removeData.
|
|
175
|
+
|
|
176
|
+
toDescribe:
|
|
177
|
+
renderView:
|
|
178
|
+
- type: TextField
|
|
179
|
+
label: "Add item:"
|
|
180
|
+
dataLocation: ~.new_item
|
|
181
|
+
placeholder: "Enter item name"
|
|
182
|
+
|
|
183
|
+
- type: button
|
|
184
|
+
content: "Add Item"
|
|
185
|
+
actions:
|
|
186
|
+
- what: addData
|
|
187
|
+
on: click
|
|
188
|
+
path: ~.items
|
|
189
|
+
value:
|
|
190
|
+
name: ~.new_item
|
|
191
|
+
when: ~.new_item
|
|
192
|
+
isNotEmpty:
|
|
193
|
+
- what: setData
|
|
194
|
+
on: click
|
|
195
|
+
path: ~.new_item
|
|
196
|
+
value: ""
|
|
197
|
+
when: ~.new_item
|
|
198
|
+
isNotEmpty:
|
|
199
|
+
|
|
200
|
+
- type: div
|
|
201
|
+
content: "Items:"
|
|
202
|
+
attributes:
|
|
203
|
+
style:
|
|
204
|
+
fontWeight: "bold"
|
|
205
|
+
margin: "10px 0 5px 0"
|
|
206
|
+
|
|
207
|
+
- type: Switch
|
|
208
|
+
content: ~.items
|
|
209
|
+
singleOption:
|
|
210
|
+
load: itemTemplate
|
|
211
|
+
|
|
212
|
+
templates:
|
|
213
|
+
itemTemplate:
|
|
214
|
+
type: div
|
|
215
|
+
content:
|
|
216
|
+
- "• "
|
|
217
|
+
- ~.name
|
|
218
|
+
- type: button
|
|
219
|
+
content: " [Remove]"
|
|
220
|
+
attributes:
|
|
221
|
+
style:
|
|
222
|
+
marginLeft: "10px"
|
|
223
|
+
background: "red"
|
|
224
|
+
color: "white"
|
|
225
|
+
border: "none"
|
|
226
|
+
padding: "2px 8px"
|
|
227
|
+
fontSize: "12px"
|
|
228
|
+
actions:
|
|
229
|
+
- what: removeData
|
|
230
|
+
on: click
|
|
231
|
+
target: currentTemplateData
|
|
232
|
+
parentLevel: 0
|
|
233
|
+
|
|
234
|
+
data:
|
|
235
|
+
new_item: ""
|
|
236
|
+
items:
|
|
237
|
+
- name: "Sample item 1"
|
|
238
|
+
- name: "Sample item 2"
|
|
239
|
+
|
|
240
|
+
- type: Markdown
|
|
241
|
+
content: |
|
|
242
|
+
## Advanced Features
|
|
243
|
+
|
|
244
|
+
### Conditional Logic
|
|
245
|
+
Reactions support the same conditional operators as actions:
|
|
246
|
+
- `when` + `is`/`isNot`: Value equality checks.
|
|
247
|
+
- `when` + `isEmpty`: Empty value tests.
|
|
248
|
+
- `when` + `contains`/`containsNot`: Content search.
|
|
249
|
+
- `when` + `>`, `<`, `>=`, `<=`: Numeric/date comparisons.
|
|
250
|
+
- `andConditions`/`orConditions`: Complex condition logic.
|
|
251
|
+
|
|
252
|
+
### Event Control
|
|
253
|
+
Use `stopPropagation: true` to:
|
|
254
|
+
1. Prevent event bubbling to parent elements.
|
|
255
|
+
2. Stop execution of subsequent actions for the same event.
|
|
256
|
+
|
|
257
|
+
### Execution Order
|
|
258
|
+
- Multiple reactions on the same event execute in the order they are defined.
|
|
259
|
+
- Reactions with unmet conditions are skipped.
|
|
260
|
+
- Actions (without `on` property) are evaluated separately from reactions.
|
|
261
|
+
|
|
262
|
+
- type: Markdown
|
|
263
|
+
content: |
|
|
264
|
+
## Technical Details
|
|
265
|
+
|
|
266
|
+
- Reactions are triggered by DOM events.
|
|
267
|
+
- Multiple reactions can be defined for the same event.
|
|
268
|
+
- Reactions are executed in the order they appear in the YAML.
|
|
269
|
+
- Reactions can be chained together by modifying data that other reactions depend on.
|
|
270
|
+
- Conditional reactions only execute when their conditions evaluate to true.
|
|
271
|
+
- The `stopPropagation` property affects both event bubbling and subsequent action execution.
|
|
272
|
+
|
|
273
|
+
## Limitations
|
|
274
|
+
|
|
275
|
+
- Event availability depends on the HTML element type (e.g., `change` only works on form elements).
|
|
276
|
+
- Network operations require proper CORS configuration.
|
|
277
|
+
- Browser operations require appropriate permissions.
|
|
278
|
+
- No built-in error handling beyond console logging for network operations.
|
|
279
|
+
- Only one network request (fetch/submit) can be active at a time.
|
|
280
|
+
- URLs in network operations must be static strings (dynamic URLs not supported).
|
|
281
|
+
|
|
282
|
+
## Best Practices
|
|
283
|
+
|
|
284
|
+
1. **Use descriptive conditions**: Make your conditional logic clear and readable.
|
|
285
|
+
2. **Handle empty states**: Always consider what happens when data is empty or undefined.
|
|
286
|
+
3. **Order matters**: Place more specific conditions before general ones.
|
|
287
|
+
4. **Use stopPropagation wisely**: Only use it when you specifically need to prevent event bubbling or stop action execution.
|
|
288
|
+
5. **Test network operations**: Ensure your API endpoints return the expected format.
|
|
289
|
+
6. **Provide user feedback**: Use visual indicators during loading states.
|
|
290
|
+
|
|
291
|
+
## Next Steps
|
|
292
|
+
|
|
293
|
+
Congratulations! You've mastered the fundamentals of Reactive-JSON. You now understand how to structure RjBuilds, use templates, and create interactive applications with actions and reactions.
|
|
294
|
+
|
|
295
|
+
Ready to take your skills further? Explore the **[Advanced Concepts](../advanced-concepts/index)** to learn about data mapping, custom plugins, and performance optimization techniques.
|
|
296
|
+
|
|
297
|
+
## Related Documentation
|
|
298
|
+
|
|
299
|
+
- **[Actions System](./actions)**: Review state-driven UI adaptation.
|
|
300
|
+
- **[Template System](./template-contexts-data-binding)**: Revisit data binding patterns.
|