@ea-lab/reactive-json-docs 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/rjbuild/docs/extend/component-development.md +14 -1
- package/public/rjbuild/docs/extend/component-development.yaml +13 -0
- package/public/rjbuild/docs/extend/plugin-system.md +69 -38
- package/public/rjbuild/docs/extend/plugin-system.yaml +118 -69
- package/public/rjbuild/docs/getting-started.md +151 -0
- package/public/rjbuild/docs/getting-started.yaml +220 -0
- package/public/rjbuild/docs/index.yaml +5 -0
- package/public/rjbuild/docs/install.md +168 -0
- package/public/rjbuild/docs/install.yaml +336 -0
- package/public/rjbuild/docs/template.md +94 -0
- package/public/rjbuild/docs/template.yaml +109 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: button
|
|
3
|
+
content: "📋 Copy initialization prompt"
|
|
4
|
+
actions:
|
|
5
|
+
- what: setClipboardData
|
|
6
|
+
on: click
|
|
7
|
+
value: |
|
|
8
|
+
# Initialization Prompt - Vite + React + @ea-lab/reactive-json Project
|
|
9
|
+
|
|
10
|
+
## ⚠️ Important Rule
|
|
11
|
+
|
|
12
|
+
**NEVER SKIP STEPS** unless explicitly requested by the user. Each step is critical for the proper functioning of the project and must be executed in the defined chronological order.
|
|
13
|
+
|
|
14
|
+
Adapt commands according to the execution environment (Windows, Ubuntu, Mac...).
|
|
15
|
+
|
|
16
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
1. [Collecting User Information](#1-collecting-user-information)
|
|
19
|
+
2. [Documentation Repositories Setup](#2-documentation-repositories-setup)
|
|
20
|
+
3. [Cursor Workspace Configuration](#3-cursor-workspace-configuration)
|
|
21
|
+
4. [Vite Project Initialization](#4-vite-project-initialization)
|
|
22
|
+
5. [Dependencies Installation](#5-dependencies-installation)
|
|
23
|
+
6. [Cursor Project Rules Creation](#6-cursor-project-rules-creation)
|
|
24
|
+
7. [Generated Project Cleanup](#7-generated-project-cleanup)
|
|
25
|
+
8. [Basic Configuration with ReactiveJsonRoot](#8-basic-configuration-with-reactivejsonroot)
|
|
26
|
+
9. [Final Verification](#9-final-verification)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Chronological Steps
|
|
31
|
+
|
|
32
|
+
### 1. Collecting User Information
|
|
33
|
+
|
|
34
|
+
**Action:** Ask the user for the following information:
|
|
35
|
+
|
|
36
|
+
- **Project name**: Will be used to create the project folder
|
|
37
|
+
- **TypeScript**: Ask if the user wants to use TypeScript (yes/no)
|
|
38
|
+
- **Documentation repositories location**: Absolute path where to clone reactive-json and reactive-json-docs repositories
|
|
39
|
+
|
|
40
|
+
**Variables to remember:**
|
|
41
|
+
- `<project_name>`: The name provided by the user
|
|
42
|
+
- `<use_typescript>`: true/false based on the answer
|
|
43
|
+
- `<docs_location>`: Absolute path for repositories
|
|
44
|
+
|
|
45
|
+
### 2. Documentation Repositories Setup
|
|
46
|
+
|
|
47
|
+
**Action:** Clone the required documentation repositories
|
|
48
|
+
|
|
49
|
+
**Commands to execute:**
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
cd <docs_location>
|
|
53
|
+
git clone https://github.com/Ealab-collab/reactive-json.git
|
|
54
|
+
git clone https://github.com/Ealab-collab/reactive-json-docs.git
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Important:** Explain to the user that these repositories are **only** for Cursor to index the documentation and will **not** be included in the final project.
|
|
58
|
+
|
|
59
|
+
**Note:** If the user indicates that the repositories are already cloned, proceed directly to step 3 (Cursor Workspace Configuration) as it is essential to add the folders to the workspace even if they already exist.
|
|
60
|
+
|
|
61
|
+
### 3. Cursor Workspace Configuration
|
|
62
|
+
|
|
63
|
+
**Action:** Ask the user to add repositories to the workspace
|
|
64
|
+
|
|
65
|
+
**Instructions to give to the user:**
|
|
66
|
+
|
|
67
|
+
> **IMPORTANT: Manual Action Required**
|
|
68
|
+
>
|
|
69
|
+
> Before continuing, you must add the cloned repositories to your Cursor workspace:
|
|
70
|
+
>
|
|
71
|
+
> 1. Go to `File > Add Folder to Workspace`
|
|
72
|
+
> 2. Add the folder `<docs_location>/reactive-json`
|
|
73
|
+
> 3. Add the folder `<docs_location>/reactive-json-docs`
|
|
74
|
+
>
|
|
75
|
+
> **Confirm that this step is completed before continuing.**
|
|
76
|
+
|
|
77
|
+
### 4. Vite Project Initialization
|
|
78
|
+
|
|
79
|
+
**Action:** Create the project with Vite
|
|
80
|
+
|
|
81
|
+
**Commands to execute:**
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# If TypeScript
|
|
85
|
+
npm create vite@latest <project_name> -- --template react-ts
|
|
86
|
+
|
|
87
|
+
# If JavaScript
|
|
88
|
+
npm create vite@latest <project_name> -- --template react
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
cd <project_name>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 5. Dependencies Installation
|
|
96
|
+
|
|
97
|
+
**Action:** Install required packages
|
|
98
|
+
|
|
99
|
+
**Commands to execute:**
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm install
|
|
103
|
+
npm install @ea-lab/reactive-json bootstrap react-bootstrap axios clsx dnd-kit-sortable-tree html-react-parser js-yaml jsonpath lodash
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 6. Cursor Project Rules Creation
|
|
107
|
+
|
|
108
|
+
**Action:** Copy Cursor rules from documentation repositories
|
|
109
|
+
|
|
110
|
+
**IMPORTANT:** This step must be done **immediately after installing dependencies** so that Cursor applies the rules during all subsequent code modifications.
|
|
111
|
+
|
|
112
|
+
**Instructions:**
|
|
113
|
+
|
|
114
|
+
1. Create the `.cursor/rules/` folder in your project:
|
|
115
|
+
```bash
|
|
116
|
+
mkdir -p .cursor/rules
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
2. Copy and merge rules from documentation repositories:
|
|
120
|
+
```bash
|
|
121
|
+
# Copy rules from reactive-json
|
|
122
|
+
cp -r <docs_location>/reactive-json/.cursor/rules/* .cursor/rules/
|
|
123
|
+
|
|
124
|
+
# Copy and merge rules from reactive-json-docs
|
|
125
|
+
cp -r <docs_location>/reactive-json-docs/.cursor/rules/* .cursor/rules/
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
These rules contain all the necessary directives to work effectively with reactive-json, including:
|
|
129
|
+
- Required documentation rules
|
|
130
|
+
- Component creation rules
|
|
131
|
+
- Code language rules
|
|
132
|
+
- And other project-specific rules
|
|
133
|
+
|
|
134
|
+
### 7. Generated Project Cleanup
|
|
135
|
+
|
|
136
|
+
**Action:** Remove/clean files generated by Vite
|
|
137
|
+
|
|
138
|
+
**Files to delete:**
|
|
139
|
+
- `src/App.css`
|
|
140
|
+
- `src/index.css` (keep only base styles)
|
|
141
|
+
- `public/vite.svg`
|
|
142
|
+
- `src/assets/react.svg`
|
|
143
|
+
|
|
144
|
+
**Files to modify:**
|
|
145
|
+
|
|
146
|
+
**`src/main.tsx` (or `src/main.jsx`):**
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import React from 'react'
|
|
150
|
+
import ReactDOM from 'react-dom/client'
|
|
151
|
+
import App from './App.tsx'
|
|
152
|
+
// Import Bootstrap styles for reactive-json
|
|
153
|
+
import 'bootstrap/dist/css/bootstrap.min.css'
|
|
154
|
+
|
|
155
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
156
|
+
<App />
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 8. Basic Configuration with ReactiveJsonRoot
|
|
161
|
+
|
|
162
|
+
**Action:** Configure the base component with an external YAML file
|
|
163
|
+
|
|
164
|
+
**IMPORTANT:** Always use an external YAML file for configuration. Never pass configuration directly in props.
|
|
165
|
+
|
|
166
|
+
**`src/App.tsx` (or `src/App.jsx`):**
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { ReactiveJsonRoot } from '@ea-lab/reactive-json'
|
|
170
|
+
import 'bootstrap/dist/css/bootstrap.min.css'
|
|
171
|
+
|
|
172
|
+
function App() {
|
|
173
|
+
return <ReactiveJsonRoot dataUrl="/config.yaml" dataFetchMethod="GET" />
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export default App
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**`public/config.yaml`:**
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
renderView:
|
|
183
|
+
- type: h1
|
|
184
|
+
content: "Ready to start!"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 9. Final Verification
|
|
188
|
+
|
|
189
|
+
**Action:** Launch development server
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npm run dev
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
If the server starts without errors and you see the "Ready to start!" message in your browser, the installation is successful. You can start developing your application with reactive-json.
|
|
196
|
+
- type: Markdown
|
|
197
|
+
content: |
|
|
198
|
+
# Reactive-JSON Installation Guide (Vite + React)
|
|
199
|
+
|
|
200
|
+
Follow the steps below to initialize a Vite + React project using `@ea-lab/reactive-json`. Do **not** skip any steps.
|
|
201
|
+
|
|
202
|
+
> **Note:** This guide assumes the use of the **Cursor** IDE to benefit from its AI assistant and automatic rules features. However, you can adapt each step and command to your preferred editor or IDE (VS Code, WebStorm, etc.).
|
|
203
|
+
|
|
204
|
+
## Detailed Installation Steps
|
|
205
|
+
|
|
206
|
+
The sections below walk you through each required action. Copy and paste the commands when provided.
|
|
207
|
+
|
|
208
|
+
### 1. Collecting User Information
|
|
209
|
+
Ask the following questions:
|
|
210
|
+
1. **Project name** (`<project_name>`)
|
|
211
|
+
2. **Use TypeScript?** (`<use_typescript>`)
|
|
212
|
+
3. **Absolute path for documentation repositories** (`<docs_location>`)
|
|
213
|
+
|
|
214
|
+
### 2. Documentation Repositories Setup
|
|
215
|
+
Execute the following commands:
|
|
216
|
+
- type: SyntaxHighlighter
|
|
217
|
+
language: bash
|
|
218
|
+
content: |
|
|
219
|
+
cd <docs_location>
|
|
220
|
+
git clone https://github.com/Ealab-collab/reactive-json.git
|
|
221
|
+
git clone https://github.com/Ealab-collab/reactive-json-docs.git
|
|
222
|
+
|
|
223
|
+
- type: Markdown
|
|
224
|
+
content: |
|
|
225
|
+
### 3. Cursor Workspace Configuration
|
|
226
|
+
**Manually** add the two cloned folders to the workspace:
|
|
227
|
+
1. `<docs_location>/reactive-json`
|
|
228
|
+
2. `<docs_location>/reactive-json-docs`
|
|
229
|
+
|
|
230
|
+
- type: Markdown
|
|
231
|
+
content: |
|
|
232
|
+
### 4. Vite Project Initialization
|
|
233
|
+
- type: SyntaxHighlighter
|
|
234
|
+
language: bash
|
|
235
|
+
content: |
|
|
236
|
+
# With TypeScript
|
|
237
|
+
npm create vite@latest <project_name> -- --template react-ts
|
|
238
|
+
# With JavaScript
|
|
239
|
+
npm create vite@latest <project_name> -- --template react
|
|
240
|
+
cd <project_name>
|
|
241
|
+
|
|
242
|
+
- type: Markdown
|
|
243
|
+
content: |
|
|
244
|
+
### 5. Dependencies Installation
|
|
245
|
+
- type: SyntaxHighlighter
|
|
246
|
+
language: bash
|
|
247
|
+
content: |
|
|
248
|
+
npm install
|
|
249
|
+
npm install @ea-lab/reactive-json bootstrap react-bootstrap axios clsx dnd-kit-sortable-tree html-react-parser js-yaml jsonpath lodash
|
|
250
|
+
|
|
251
|
+
- type: Markdown
|
|
252
|
+
content: |
|
|
253
|
+
### 6. Cursor Rules Creation
|
|
254
|
+
Copy rules from documentation repositories **before any code modification**.
|
|
255
|
+
- type: SyntaxHighlighter
|
|
256
|
+
language: bash
|
|
257
|
+
content: |
|
|
258
|
+
# Create rules directory
|
|
259
|
+
mkdir -p .cursor/rules
|
|
260
|
+
|
|
261
|
+
# Copy rules from reactive-json
|
|
262
|
+
cp -r <docs_location>/reactive-json/.cursor/rules/* .cursor/rules/
|
|
263
|
+
|
|
264
|
+
# Copy and merge rules from reactive-json-docs
|
|
265
|
+
cp -r <docs_location>/reactive-json-docs/.cursor/rules/* .cursor/rules/
|
|
266
|
+
|
|
267
|
+
- type: Markdown
|
|
268
|
+
content: |
|
|
269
|
+
These rules contain all the necessary directives to work effectively with reactive-json, including:
|
|
270
|
+
- Required documentation rules
|
|
271
|
+
- Component creation rules
|
|
272
|
+
- Code language rules
|
|
273
|
+
- And other project-specific rules
|
|
274
|
+
|
|
275
|
+
- type: Markdown
|
|
276
|
+
content: |
|
|
277
|
+
### 7. Vite Project Cleanup
|
|
278
|
+
Remove unnecessary files (`App.css`, `index.css`, `vite.svg`, `react.svg`) and modify `src/main.tsx`:
|
|
279
|
+
|
|
280
|
+
- type: Markdown
|
|
281
|
+
content: |
|
|
282
|
+
**File: src/main.tsx**
|
|
283
|
+
- type: SyntaxHighlighter
|
|
284
|
+
language: typescript
|
|
285
|
+
content: |
|
|
286
|
+
import React from 'react'
|
|
287
|
+
import ReactDOM from 'react-dom/client'
|
|
288
|
+
import App from './App.tsx'
|
|
289
|
+
import 'bootstrap/dist/css/bootstrap.min.css'
|
|
290
|
+
|
|
291
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
292
|
+
<App />
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
- type: Markdown
|
|
296
|
+
content: |
|
|
297
|
+
### 8. Basic Configuration with ReactiveJsonRoot
|
|
298
|
+
|
|
299
|
+
- type: Markdown
|
|
300
|
+
content: |
|
|
301
|
+
**File: src/App.tsx**
|
|
302
|
+
- type: SyntaxHighlighter
|
|
303
|
+
language: typescript
|
|
304
|
+
content: |
|
|
305
|
+
import { ReactiveJsonRoot } from '@ea-lab/reactive-json'
|
|
306
|
+
import 'bootstrap/dist/css/bootstrap.min.css'
|
|
307
|
+
|
|
308
|
+
function App() {
|
|
309
|
+
return <ReactiveJsonRoot dataUrl="/config.yaml" dataFetchMethod="GET" />
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export default App
|
|
313
|
+
|
|
314
|
+
- type: Markdown
|
|
315
|
+
content: |
|
|
316
|
+
**File: public/config.yaml**
|
|
317
|
+
- type: SyntaxHighlighter
|
|
318
|
+
language: yaml
|
|
319
|
+
content: |
|
|
320
|
+
renderView:
|
|
321
|
+
- type: h1
|
|
322
|
+
content: "Ready to start!"
|
|
323
|
+
|
|
324
|
+
- type: Markdown
|
|
325
|
+
content: |
|
|
326
|
+
### 9. Final Verification
|
|
327
|
+
- type: SyntaxHighlighter
|
|
328
|
+
language: bash
|
|
329
|
+
content: |
|
|
330
|
+
npm run dev
|
|
331
|
+
|
|
332
|
+
# Open http://localhost:5173 and verify that "Ready to start!" is displayed.
|
|
333
|
+
|
|
334
|
+
templates:
|
|
335
|
+
|
|
336
|
+
data: {}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Template and Context System
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
The template system in reactive-json efficiently manages data contexts and their access. Understanding how templates "containerize" data is essential for properly using components, actions, and reactions.
|
|
6
|
+
|
|
7
|
+
## Context Notations
|
|
8
|
+
|
|
9
|
+
There are three main notations for accessing data:
|
|
10
|
+
|
|
11
|
+
- `~.` : Local context (relative to current template)
|
|
12
|
+
- `~~.` : Global context (access to global data)
|
|
13
|
+
- `~>field` : Access to a specific parent context by climbing up to a given key
|
|
14
|
+
|
|
15
|
+
### Context Usage Example
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
templates:
|
|
19
|
+
userList:
|
|
20
|
+
type: Switch
|
|
21
|
+
content: ~~.users
|
|
22
|
+
template:
|
|
23
|
+
type: div
|
|
24
|
+
content:
|
|
25
|
+
- type: div
|
|
26
|
+
content: ["Name: ", ~.name] # Local access to current user data
|
|
27
|
+
- type: div
|
|
28
|
+
content: ["Admin: ", ~~.isAdmin] # Global access to isAdmin data
|
|
29
|
+
- type: div
|
|
30
|
+
content: ["Parent: ", ~>userList.title] # Climbs up to 'userList' template to access title
|
|
31
|
+
|
|
32
|
+
data:
|
|
33
|
+
users:
|
|
34
|
+
- name: "John"
|
|
35
|
+
isAdmin: true
|
|
36
|
+
userList:
|
|
37
|
+
title: "User List"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
In this example:
|
|
41
|
+
- `~.name` accesses the `name` property from the local context (current user)
|
|
42
|
+
- `~~.isAdmin` accesses the `isAdmin` property from the global context
|
|
43
|
+
- `~>userList.title` climbs up to the "userList" template and accesses its `title` property
|
|
44
|
+
|
|
45
|
+
## Containerization Principle
|
|
46
|
+
|
|
47
|
+
Templates create context "containers". This means each template defines its own local data space.
|
|
48
|
+
|
|
49
|
+
### Impact on Components
|
|
50
|
+
|
|
51
|
+
This containerization affects several aspects:
|
|
52
|
+
|
|
53
|
+
1. **Forms**: Form fields using `~.` access data from their defining template
|
|
54
|
+
2. **Actions**: Actions using `~.` modify data within the template context
|
|
55
|
+
3. **Reactions**: Reactions can access different levels depending on the prefix used
|
|
56
|
+
|
|
57
|
+
### Form Context Example
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
templates:
|
|
61
|
+
editForm:
|
|
62
|
+
type: form
|
|
63
|
+
content:
|
|
64
|
+
- type: TextField
|
|
65
|
+
path: ~.temp_name # Local modification
|
|
66
|
+
value: ~.name # Initial value
|
|
67
|
+
- type: button
|
|
68
|
+
content: "Save"
|
|
69
|
+
actions:
|
|
70
|
+
- what: setData
|
|
71
|
+
on: click
|
|
72
|
+
path: ~~.globalUser.name # Global save
|
|
73
|
+
value: ~.temp_name # Uses temporary value
|
|
74
|
+
|
|
75
|
+
data:
|
|
76
|
+
temp_name: ""
|
|
77
|
+
name: "John"
|
|
78
|
+
globalUser:
|
|
79
|
+
name: "John"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Key Points to Remember
|
|
83
|
+
|
|
84
|
+
1. Two components using `~.` in different templates access different data
|
|
85
|
+
2. Actions and reactions respect the context where they are defined
|
|
86
|
+
3. Containerization allows isolating modifications until validation
|
|
87
|
+
4. `~~.` allows "escaping" the container to access global data
|
|
88
|
+
5. `~>field` allows climbing up to a specific parent context using the template name as reference
|
|
89
|
+
|
|
90
|
+
## Best Practices
|
|
91
|
+
|
|
92
|
+
1. **Context Coherence**: Ensure components that need to share data are in the same context
|
|
93
|
+
2. **Global Access**: Use `~~.` for data that needs to be shared between different templates
|
|
94
|
+
3. **Hierarchical Navigation**: Use `~>field` to access specific parent template data by explicitly naming it
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# Template and Context System
|
|
5
|
+
|
|
6
|
+
## Introduction
|
|
7
|
+
|
|
8
|
+
The template system in reactive-json efficiently manages data contexts and their access. Understanding how templates "containerize" data is essential for properly using components, actions, and reactions.
|
|
9
|
+
|
|
10
|
+
- type: RjBuildDescriber
|
|
11
|
+
title: "Context Notations"
|
|
12
|
+
description:
|
|
13
|
+
- type: Markdown
|
|
14
|
+
content: |
|
|
15
|
+
There are three main notations for accessing data:
|
|
16
|
+
|
|
17
|
+
- `~.` : Local context (relative to current template)
|
|
18
|
+
- `~~.` : Global context (access to global data)
|
|
19
|
+
- `~>field` : Access to a specific parent context by climbing up to a given key
|
|
20
|
+
|
|
21
|
+
toDescribe:
|
|
22
|
+
templates:
|
|
23
|
+
userList:
|
|
24
|
+
type: Switch
|
|
25
|
+
content: ~~.users
|
|
26
|
+
template:
|
|
27
|
+
type: div
|
|
28
|
+
content:
|
|
29
|
+
- type: div
|
|
30
|
+
content: ["Name: ", ~.name] # Local access to current user data
|
|
31
|
+
- type: div
|
|
32
|
+
content: ["Admin: ", ~~.isAdmin] # Global access to isAdmin data
|
|
33
|
+
- type: div
|
|
34
|
+
content: ["Parent: ", ~>userList.title] # Climbs up to 'userList' template to access title
|
|
35
|
+
|
|
36
|
+
data:
|
|
37
|
+
users:
|
|
38
|
+
- name: "John"
|
|
39
|
+
isAdmin: true
|
|
40
|
+
userList:
|
|
41
|
+
title: "User List"
|
|
42
|
+
|
|
43
|
+
- type: Markdown
|
|
44
|
+
content: |
|
|
45
|
+
In this example:
|
|
46
|
+
- `~.name` accesses the `name` property from the local context (current user)
|
|
47
|
+
- `~~.isAdmin` accesses the `isAdmin` property from the global context
|
|
48
|
+
- `~>userList.title` climbs up to the "userList" template and accesses its `title` property
|
|
49
|
+
|
|
50
|
+
## Containerization Principle
|
|
51
|
+
|
|
52
|
+
Templates create context "containers". This means each template defines its own local data space.
|
|
53
|
+
|
|
54
|
+
### Impact on Components
|
|
55
|
+
|
|
56
|
+
This containerization affects several aspects:
|
|
57
|
+
|
|
58
|
+
1. **Forms**: Form fields using `~.` access data from their defining template
|
|
59
|
+
2. **Actions**: Actions using `~.` modify data within the template context
|
|
60
|
+
3. **Reactions**: Reactions can access different levels depending on the prefix used
|
|
61
|
+
|
|
62
|
+
- type: RjBuildDescriber
|
|
63
|
+
title: "Form Context Example"
|
|
64
|
+
description:
|
|
65
|
+
- type: Markdown
|
|
66
|
+
content: |
|
|
67
|
+
This example shows how a form uses local context for editing before saving to the global context.
|
|
68
|
+
|
|
69
|
+
toDescribe:
|
|
70
|
+
templates:
|
|
71
|
+
editForm:
|
|
72
|
+
type: form
|
|
73
|
+
content:
|
|
74
|
+
- type: TextField
|
|
75
|
+
path: ~.temp_name # Local modification
|
|
76
|
+
value: ~.name # Initial value
|
|
77
|
+
- type: button
|
|
78
|
+
content: "Save"
|
|
79
|
+
actions:
|
|
80
|
+
- what: setData
|
|
81
|
+
on: click
|
|
82
|
+
path: ~~.globalUser.name # Global save
|
|
83
|
+
value: ~.temp_name # Uses temporary value
|
|
84
|
+
|
|
85
|
+
data:
|
|
86
|
+
temp_name: ""
|
|
87
|
+
name: "John"
|
|
88
|
+
globalUser:
|
|
89
|
+
name: "John"
|
|
90
|
+
|
|
91
|
+
- type: Markdown
|
|
92
|
+
content: |
|
|
93
|
+
## Key Points to Remember
|
|
94
|
+
|
|
95
|
+
1. Two components using `~.` in different templates access different data
|
|
96
|
+
2. Actions and reactions respect the context where they are defined
|
|
97
|
+
3. Containerization allows isolating modifications until validation
|
|
98
|
+
4. `~~.` allows "escaping" the container to access global data
|
|
99
|
+
5. `~>field` allows climbing up to a specific parent context using the template name as reference
|
|
100
|
+
|
|
101
|
+
## Best Practices
|
|
102
|
+
|
|
103
|
+
1. **Context Coherence**: Ensure components that need to share data are in the same context
|
|
104
|
+
2. **Global Access**: Use `~~.` for data that needs to be shared between different templates
|
|
105
|
+
3. **Hierarchical Navigation**: Use `~>field` to access specific parent template data by explicitly naming it
|
|
106
|
+
|
|
107
|
+
templates:
|
|
108
|
+
|
|
109
|
+
data: {}
|