@ea-lab/reactive-json-docs 1.0.0-alpha.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/attribute-transformers.md +168 -0
- package/public/rjbuild/docs/advanced-concepts/attribute-transformers.yaml +151 -0
- package/public/rjbuild/docs/advanced-concepts/data-mapping.md +6 -6
- package/public/rjbuild/docs/advanced-concepts/data-mapping.yaml +7 -7
- package/public/rjbuild/docs/advanced-concepts/data-processors.md +7 -7
- package/public/rjbuild/docs/advanced-concepts/data-processors.yaml +7 -7
- package/public/rjbuild/docs/advanced-concepts/forward-update.md +82 -9
- package/public/rjbuild/docs/advanced-concepts/forward-update.yaml +83 -13
- package/public/rjbuild/docs/advanced-concepts/index.md +1 -0
- package/public/rjbuild/docs/advanced-concepts/index.yaml +1 -0
- package/public/rjbuild/docs/advanced-concepts/plugins/component-development.md +1 -1
- package/public/rjbuild/docs/advanced-concepts/plugins/component-development.yaml +1 -1
- package/public/rjbuild/docs/advanced-concepts/plugins/plugin-system.md +1 -1
- package/public/rjbuild/docs/advanced-concepts/plugins/plugin-system.yaml +1 -1
- package/public/rjbuild/docs/core/action/Attribute/SetAttributeValue.md +2 -0
- package/public/rjbuild/docs/core/action/Attribute/SetAttributeValue.yaml +2 -0
- package/public/rjbuild/docs/core/action/Attribute/ToggleAttributeValue.md +2 -0
- package/public/rjbuild/docs/core/action/Attribute/ToggleAttributeValue.yaml +2 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttribute.md +2 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttribute.yaml +2 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttributeValue.md +2 -0
- package/public/rjbuild/docs/core/action/Attribute/UnsetAttributeValue.yaml +2 -0
- package/public/rjbuild/docs/core/action/Attribute/index.md +121 -0
- package/public/rjbuild/docs/core/action/Attribute/index.yaml +77 -0
- 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/attributeTransformer/index.md +17 -0
- package/public/rjbuild/docs/core/attributeTransformer/index.yaml +24 -0
- package/public/rjbuild/docs/core/attributeTransformer/setAttributeValue.md +101 -0
- package/public/rjbuild/docs/core/attributeTransformer/setAttributeValue.yaml +144 -0
- package/public/rjbuild/docs/core/attributeTransformer/toggleAttributeValue.md +269 -0
- package/public/rjbuild/docs/core/attributeTransformer/toggleAttributeValue.yaml +247 -0
- package/public/rjbuild/docs/core/attributeTransformer/unsetAttribute.md +114 -0
- package/public/rjbuild/docs/core/attributeTransformer/unsetAttribute.yaml +138 -0
- package/public/rjbuild/docs/core/attributeTransformer/unsetAttributeValue.md +140 -0
- package/public/rjbuild/docs/core/attributeTransformer/unsetAttributeValue.yaml +187 -0
- package/public/rjbuild/docs/core/hook/index.md +38 -0
- package/public/rjbuild/docs/core/hook/index.yaml +44 -0
- package/public/rjbuild/docs/core/hook/usePagination.md +286 -0
- package/public/rjbuild/docs/core/hook/usePagination.yaml +319 -0
- package/public/rjbuild/docs/core/hook/useTransformedAttributes.md +130 -0
- package/public/rjbuild/docs/core/hook/useTransformedAttributes.yaml +164 -0
- 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
|
@@ -1,17 +1,11 @@
|
|
|
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
|
-
# Forward
|
|
4
|
+
# Forward update
|
|
11
5
|
|
|
12
6
|
> Use the special placeholder `<reactive-json:event>` to reference values coming directly from the DOM or custom event that triggered a reaction.
|
|
13
7
|
|
|
14
|
-
The **Forward
|
|
8
|
+
The **Forward update** pattern lets you use the special placeholder `<reactive-json:event>` inside any reaction arguments.
|
|
15
9
|
It is primarily useful with `setData`, but can be applied to any reaction.
|
|
16
10
|
Instead of reading a value *after* the global data has been updated, you can forward the fresh value carried by the event itself.
|
|
17
11
|
|
|
@@ -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: {}
|
|
@@ -4,6 +4,7 @@ This section covers advanced features and concepts in Reactive-JSON that enable
|
|
|
4
4
|
|
|
5
5
|
## Topics
|
|
6
6
|
|
|
7
|
+
- **[Attribute Transformers](attribute-transformers.md)**: Details on how element attributes can be modified by the app state.
|
|
7
8
|
- **[Data Mapping](data-mapping.md)**: Learn how to selectively dispatch and transform response data using the Data Mapping system
|
|
8
9
|
- **[Data Processors](data-processors.md)**: Learn how to intercept and modify data from HTTP requests using the DataProcessor system
|
|
9
10
|
- **[Forward Update](forward-update.md)**: Implementation details about the retrieval of event values.
|
|
@@ -7,6 +7,7 @@ renderView:
|
|
|
7
7
|
|
|
8
8
|
## Topics
|
|
9
9
|
|
|
10
|
+
- **[Attribute Transformers](attribute-transformers)**: Details on how element attributes can be modified by the app state.
|
|
10
11
|
- **[Data Mapping](data-mapping)**: Learn how to selectively dispatch and transform response data using the Data Mapping system.
|
|
11
12
|
- **[Data Processors](data-processors)**: Learn how to intercept and modify data from HTTP requests using the DataProcessor system.
|
|
12
13
|
- **[Forward Update](forward-update)**: Implementation details about the retrieval of event values.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# SetAttributeValue
|
|
2
2
|
|
|
3
|
+
> **Alternative**: For pre-render attribute modification, see the [setAttributeValue transformer](../../attributeTransformer/setAttributeValue.md).
|
|
4
|
+
|
|
3
5
|
Dynamically sets or modifies the value of an HTML attribute on an element.
|
|
4
6
|
|
|
5
7
|
## Basic Syntax
|
|
@@ -3,6 +3,8 @@ renderView:
|
|
|
3
3
|
content: |
|
|
4
4
|
# SetAttributeValue
|
|
5
5
|
|
|
6
|
+
> **Alternative**: For pre-render attribute modification, see the [setAttributeValue transformer](../../attributeTransformer/setAttributeValue).
|
|
7
|
+
|
|
6
8
|
Dynamically sets or modifies the value of an HTML attribute on an element.
|
|
7
9
|
|
|
8
10
|
## Basic Syntax
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# ToggleAttributeValue
|
|
2
2
|
|
|
3
|
+
> **Alternative**: For pre-render attribute modification, see the [toggleAttributeValue transformer](../../attributeTransformer/toggleAttributeValue.md).
|
|
4
|
+
|
|
3
5
|
Toggles the presence of a specific value in an HTML attribute. Supports both simple on-off toggles and cyclic toggling through multiple values.
|
|
4
6
|
|
|
5
7
|
## Important Notes
|
|
@@ -3,6 +3,8 @@ renderView:
|
|
|
3
3
|
content: |
|
|
4
4
|
# ToggleAttributeValue
|
|
5
5
|
|
|
6
|
+
> **Alternative**: For pre-render attribute modification, see the [toggleAttributeValue transformer](../../attributeTransformer/toggleAttributeValue).
|
|
7
|
+
|
|
6
8
|
Toggles the presence of a specific value in an HTML attribute. Supports both simple on-off toggles and cyclic toggling through multiple values.
|
|
7
9
|
|
|
8
10
|
## Important Notes
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# UnsetAttributeValue
|
|
2
2
|
|
|
3
|
+
> **Alternative**: For pre-render attribute modification, see the [unsetAttributeValue transformer](../../attributeTransformer/unsetAttributeValue.md).
|
|
4
|
+
|
|
3
5
|
Removes a specific value from an HTML attribute while preserving other values.
|
|
4
6
|
|
|
5
7
|
## Basic Syntax
|
|
@@ -3,6 +3,8 @@ renderView:
|
|
|
3
3
|
content: |
|
|
4
4
|
# UnsetAttributeValue
|
|
5
5
|
|
|
6
|
+
> **Alternative**: For pre-render attribute modification, see the [unsetAttributeValue transformer](../../attributeTransformer/unsetAttributeValue).
|
|
7
|
+
|
|
6
8
|
Removes a specific value from an HTML attribute while preserving other values.
|
|
7
9
|
|
|
8
10
|
## Basic Syntax
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Attribute Actions
|
|
2
|
+
|
|
3
|
+
> **Note**: Reactive-JSON provides two systems for attribute modification:
|
|
4
|
+
>
|
|
5
|
+
> - **Attribute Actions** (this section): Execute **after rendering**, modify DOM attributes directly
|
|
6
|
+
> - **[Attribute Transformers](../../attributeTransformer/index.md)**: Execute **before rendering**, modify attributes for child components
|
|
7
|
+
>
|
|
8
|
+
> Choose actions for post-render DOM manipulation and transformers for pre-render attribute conditioning.
|
|
9
|
+
|
|
10
|
+
Attribute Actions in Reactive-JSON allow you to modify element attributes after rendering based on dynamic conditions. They are evaluated continuously based on data state and provide direct DOM manipulation capabilities.
|
|
11
|
+
|
|
12
|
+
## Key Differences from Transformers
|
|
13
|
+
|
|
14
|
+
- **Timing**: Attribute actions execute **after rendering**, while transformers execute **before rendering**
|
|
15
|
+
- **Impact**: Actions modify the DOM directly, transformers affect attributes passed to child components
|
|
16
|
+
- **Use case**: Actions are ideal for imperative DOM updates that don't need to affect child component props
|
|
17
|
+
|
|
18
|
+
## Available Attribute Actions
|
|
19
|
+
|
|
20
|
+
### Value Management
|
|
21
|
+
- **[SetAttributeValue](./SetAttributeValue.md)**: Sets or modifies HTML attribute values dynamically after rendering
|
|
22
|
+
- **[UnsetAttributeValue](./UnsetAttributeValue.md)**: Removes specific values from HTML attributes while preserving others
|
|
23
|
+
- **[ToggleAttributeValue](./ToggleAttributeValue.md)**: Toggles the presence of specific values in HTML attributes, supports cyclic toggling
|
|
24
|
+
|
|
25
|
+
### Attribute Management
|
|
26
|
+
- **[UnsetAttribute](./UnsetAttribute.md)**: Completely removes HTML attributes after rendering
|
|
27
|
+
|
|
28
|
+
## Basic Usage
|
|
29
|
+
|
|
30
|
+
Attribute actions are defined in the `actions` array on any element:
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
renderView:
|
|
34
|
+
- type: div
|
|
35
|
+
attributes:
|
|
36
|
+
class: "base-class"
|
|
37
|
+
data-status: "default"
|
|
38
|
+
actions:
|
|
39
|
+
# Add class conditionally
|
|
40
|
+
- what: SetAttributeValue
|
|
41
|
+
name: "class"
|
|
42
|
+
value: "active"
|
|
43
|
+
when: ~~.isActive
|
|
44
|
+
is: true
|
|
45
|
+
|
|
46
|
+
# Remove attribute entirely
|
|
47
|
+
- what: UnsetAttribute
|
|
48
|
+
name: "data-status"
|
|
49
|
+
when: ~~.hideStatus
|
|
50
|
+
is: true
|
|
51
|
+
|
|
52
|
+
# Toggle between states
|
|
53
|
+
- what: ToggleAttributeValue
|
|
54
|
+
name: "class"
|
|
55
|
+
value: ["theme-light", "theme-dark"]
|
|
56
|
+
when: ~~.toggleTheme
|
|
57
|
+
isNotEmpty:
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Execution Order
|
|
61
|
+
|
|
62
|
+
Attribute actions are applied based on data changes and re-evaluated when dependencies change:
|
|
63
|
+
|
|
64
|
+
1. Component renders with base attributes
|
|
65
|
+
2. Actions are evaluated based on current data state
|
|
66
|
+
3. DOM attributes are modified directly
|
|
67
|
+
4. Changes are applied to the live DOM element
|
|
68
|
+
|
|
69
|
+
## Conditional Execution
|
|
70
|
+
|
|
71
|
+
All attribute actions support the same conditional system as other actions:
|
|
72
|
+
|
|
73
|
+
- **`when`**: Specifies the data value to evaluate
|
|
74
|
+
- **`is`**: Exact value comparison
|
|
75
|
+
- **`isEmpty`/`isNotEmpty`**: Empty/non-empty checks
|
|
76
|
+
- **Template evaluation**: Full support for `~.`, `~~.`, `~>`, `~~>` patterns
|
|
77
|
+
|
|
78
|
+
## Common Patterns
|
|
79
|
+
|
|
80
|
+
### Conditional Styling
|
|
81
|
+
```yaml
|
|
82
|
+
actions:
|
|
83
|
+
- what: SetAttributeValue
|
|
84
|
+
name: "class"
|
|
85
|
+
value: "error"
|
|
86
|
+
when: ~~.validation.hasErrors
|
|
87
|
+
is: true
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### State-based Attributes
|
|
91
|
+
```yaml
|
|
92
|
+
actions:
|
|
93
|
+
- what: ToggleAttributeValue
|
|
94
|
+
name: "aria-expanded"
|
|
95
|
+
value: "true"
|
|
96
|
+
when: ~~.menu.isOpen
|
|
97
|
+
is: true
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Dynamic Data Attributes
|
|
101
|
+
```yaml
|
|
102
|
+
actions:
|
|
103
|
+
- what: SetAttributeValue
|
|
104
|
+
name: "data-user-role"
|
|
105
|
+
value: ~~.currentUser.role
|
|
106
|
+
mode: "replace"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## When to Use Actions vs Transformers
|
|
110
|
+
|
|
111
|
+
### Use Attribute Actions when:
|
|
112
|
+
- You need to modify DOM attributes after the component has rendered
|
|
113
|
+
- You're working with imperative DOM updates
|
|
114
|
+
- You need to interact with external libraries that read DOM attributes
|
|
115
|
+
- The attribute changes don't need to affect child component behavior
|
|
116
|
+
|
|
117
|
+
### Use Attribute Transformers when:
|
|
118
|
+
- You need attributes to be available to child components
|
|
119
|
+
- You're doing conditional attribute setup before rendering
|
|
120
|
+
- You want predictable attribute values during the render phase
|
|
121
|
+
- You're building reusable components that depend on specific attributes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# Attribute Actions
|
|
5
|
+
|
|
6
|
+
> **Note**: Reactive-JSON provides two systems for attribute modification:
|
|
7
|
+
>
|
|
8
|
+
> - **Attribute Actions** (this section): Execute **after rendering**, modify DOM attributes directly
|
|
9
|
+
> - **[Attribute Transformers](../../attributeTransformer/index)**: Execute **before rendering**, modify attributes for child components
|
|
10
|
+
>
|
|
11
|
+
> Choose actions for post-render DOM manipulation and transformers for pre-render attribute conditioning.
|
|
12
|
+
|
|
13
|
+
Attribute Actions in Reactive-JSON allow you to modify element attributes after rendering based on dynamic conditions. They are evaluated continuously based on data state and provide direct DOM manipulation capabilities.
|
|
14
|
+
|
|
15
|
+
- type: TabbedSerializer
|
|
16
|
+
yamlSerializedContent: |
|
|
17
|
+
renderView:
|
|
18
|
+
- type: div
|
|
19
|
+
attributes:
|
|
20
|
+
class: "base-class"
|
|
21
|
+
data-status: "default"
|
|
22
|
+
actions:
|
|
23
|
+
# Add class conditionally
|
|
24
|
+
- what: SetAttributeValue
|
|
25
|
+
name: "class"
|
|
26
|
+
value: "active"
|
|
27
|
+
when: ~~.isActive
|
|
28
|
+
is: true
|
|
29
|
+
|
|
30
|
+
# Remove attribute entirely
|
|
31
|
+
- what: UnsetAttribute
|
|
32
|
+
name: "data-status"
|
|
33
|
+
when: ~~.hideStatus
|
|
34
|
+
is: true
|
|
35
|
+
|
|
36
|
+
# Toggle between states
|
|
37
|
+
- what: ToggleAttributeValue
|
|
38
|
+
name: "class"
|
|
39
|
+
value: ["theme-light", "theme-dark"]
|
|
40
|
+
when: ~~.toggleTheme
|
|
41
|
+
isNotEmpty:
|
|
42
|
+
|
|
43
|
+
- type: Markdown
|
|
44
|
+
content: |
|
|
45
|
+
## Key Differences from Transformers
|
|
46
|
+
|
|
47
|
+
- **Timing**: Attribute actions execute **after rendering**, while transformers execute **before rendering**
|
|
48
|
+
- **Impact**: Actions modify the DOM directly, transformers affect attributes passed to child components
|
|
49
|
+
- **Use case**: Actions are ideal for imperative DOM updates that don't need to affect child component props
|
|
50
|
+
|
|
51
|
+
## Available Attribute Actions
|
|
52
|
+
|
|
53
|
+
### Value Management
|
|
54
|
+
- **[SetAttributeValue](./SetAttributeValue)**: Sets or modifies HTML attribute values dynamically after rendering
|
|
55
|
+
- **[UnsetAttributeValue](./UnsetAttributeValue)**: Removes specific values from HTML attributes while preserving others
|
|
56
|
+
- **[ToggleAttributeValue](./ToggleAttributeValue)**: Toggles the presence of specific values in HTML attributes, supports cyclic toggling
|
|
57
|
+
|
|
58
|
+
### Attribute Management
|
|
59
|
+
- **[UnsetAttribute](./UnsetAttribute)**: Completely removes HTML attributes after rendering
|
|
60
|
+
|
|
61
|
+
## Execution Order
|
|
62
|
+
|
|
63
|
+
Attribute actions are applied based on data changes and re-evaluated when dependencies change:
|
|
64
|
+
|
|
65
|
+
1. Component renders with base attributes
|
|
66
|
+
2. Actions are evaluated based on current data state
|
|
67
|
+
3. DOM attributes are modified directly
|
|
68
|
+
4. Changes are applied to the live DOM element
|
|
69
|
+
|
|
70
|
+
## Conditional Execution
|
|
71
|
+
|
|
72
|
+
All attribute actions support the same conditional system as other actions:
|
|
73
|
+
|
|
74
|
+
- **`when`**: Specifies the data value to evaluate
|
|
75
|
+
- **`is`**: Exact value comparison
|
|
76
|
+
- **`isEmpty`/`isNotEmpty`**: Empty/non-empty checks
|
|
77
|
+
- **Template evaluation**: Full support for `~.`, `~~.`, `~>`, `~~>` patterns
|
|
@@ -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
|