@@ -17,26 +17,23 @@ Feel free to choose one of them and adapt it to your needs.
17
17
18
18
## 🚀 Inspiration 1
19
19
20
- In this Style-Guide, we have a so-called ` core ` at the top-level of our ` src ` folder beside our UI-Components.
20
+ In this Style-Guide, we have a so-called ` core ` at the top-level of our ` src ` folder, besides our UI-Components.
21
21
The ` core ` is thought to be the brain of our application and should contain all business logic
22
- and logic in general, that isn't specifically bound to a Component.
22
+ and logic in general that isn't explicitly bound to a Component.
23
23
This outsourcing of our logic makes our code more decoupled,
24
24
portable, and above all easy testable.
25
25
26
- Below you can see where our ` core ` should be located.
27
-
26
+ Below you see where our ` core ` might be located in the main tree.
28
27
``` js {3} title="MyApp"
29
28
my- app
30
29
├── src
31
30
│ └── core
32
31
│ └── render
33
32
.
34
33
```
35
-
36
- To represent the ` core ` for a better understanding visual, I use one of a TODO application.
37
- This application has two main [ Entities] ( #📁-entities ) , that can be handled by AgileTs.
38
- The ** User** and of course the ** TODO-Item** . These two parts are mapped in our ` core ` .
39
-
34
+ We use the ` core ` of a simple TODO application to visually illustrate how such a ` core ` can be constructed.
35
+ Our todo application has two main [ Entities] ( #📁-entities ) , that AgileTs can handle.
36
+ The ** User** and of course, the ** TODO-Item** . These two parts are mapped in our ` core ` .
40
37
``` js title="TodoList-Core"
41
38
core
42
39
│── api
58
55
| ── index .ts
59
56
.
60
57
```
61
- Each property that you can find in the above shown graph , is described in detail below ⬇️.
58
+ Each property you find above in the folder structure of the ` TodoList-Core ` , is described in detail below ⬇️.
62
59
63
60
## 📁 api
64
61
65
- Our Todo-List has to communicate to a ** Backend** , therefore we need something that creates http/s requests for us.
66
- I am using the [ AgileTs API] ( ../packages/api/Introduction.md ) but you can use whatever you want.
62
+ Our Todo-List has to communicate to a ` backend ` . Therefore, we need something that creates http/s requests for us.
63
+ In the example, we use the [ AgileTs API] ( ../packages/api/Introduction.md ) but you can use whatever you want.
64
+ If your application doesn't need to communicate to a ` backend, ` you can entirely skip the ` api ` section.
67
65
68
66
### 📝 index.ts
69
67
70
- To make simple rest calls possible, we initialize our api class here .
71
- These defined API instance gets mainly used in the [ route] ( #📝-.routes.ts ) section of an Entity.
72
-
68
+ To make rest calls possible, we initialize our api class in the ` index ` file in the ` api ` folder .
69
+ The defined API Instance will be mainly used in the [ route] ( #-routets ) file of an [ Entity] ( #-entities ) ,
70
+ where we define the single routes to the backend.
73
71
``` ts title="index.ts"
74
72
import API from ' @agile-ts/api' ;
75
73
@@ -82,23 +80,21 @@ const api = new API({
82
80
});
83
81
84
82
export default api ;
85
-
86
83
```
87
84
88
85
## 📁 entities
89
86
90
- Our ` core ` consists of several entities, which exist apart from each other, having their own independent existence. Each
91
- Entity manages its Data separately by doing rest calls or mutating States. This separation makes our ` core ` more
92
- structured, readable, and improves maintainability.
87
+ Our ` core ` consists of several entities, which exist apart from each other, having their own independent existence.
88
+ Each ` Entity ` manages its Data separately by doing rest calls or mutating States. This separation makes our ` core ` more
89
+ structured, readable and improves maintainability.
93
90
94
91
** For instance:** <br />
95
- A _ User Entity_ should only treat the whole logic of the User and shouldn't do rest calls for the _ Todo Entity_ .
92
+ The _ User Entity_ should only treat the user's whole logic and shouldn't do rest calls, for instance, for the _ Todo Entity_ .
96
93
97
94
### 📝 index.ts
98
95
99
- Here we just export all [ actions] ( #📝-.action.ts ) , [ routes] ( #📝-.routes.ts ) , [ interfaces] ( #📝-.interface.ts ) and
100
- the [ controller] ( #📝-.controller.ts ) . To properly import them in our UI-Layer later.
101
-
96
+ Here we just export all [ actions] ( #-actionts ) , [ routes] ( #-routets ) , [ interfaces] ( #-interfacets ) and
97
+ the [ controller] ( #-controllerts ) . To properly import them in our UI-Layer later, like ` core.todo.createTodo() ` .
102
98
``` ts title="index.ts in 📁todo"
103
99
import * as actions from " ./todo.actions" ;
104
100
import * as controller from " ./todo.controller" ;
@@ -115,11 +111,13 @@ export default {
115
111
116
112
### 📝 .action.ts
117
113
118
- An action is any piece of code that modifies our ` State ` .
119
- In principle, actions always happen in response to an event. For example, a button got clicked.
114
+ An action does handle the logic of our Entity. We should name the actions after action names like ` createX ` , ` removeY ` .
115
+ In general, an action modifies the ` State ` , makes rest calls through the functions provided by the [ route.ts] ( #-routets ) file
116
+ , and computes some values if necessary.
117
+ In principle, actions always happen in response to an event. For example, if the add todo button got clicked.
120
118
121
119
** For instance:** <br />
122
- The creation of a Todo-Item in the UI-Layer triggers the ` addTodo ` action, which then mutates our State and makes rest calls.
120
+ The creation of a Todo-Item in the UI-Layer triggers the ` addTodo() ` action, which then mutates our State and makes rest calls.
123
121
124
122
``` ts title="todo.action.ts in 📁todo"
125
123
import {TodoInterface } from ' ./todo.interface' ;
@@ -140,9 +138,8 @@ export const addTodo = async (userId: string, description: string): Promise<void
140
138
141
139
### 📝 .controller.ts
142
140
143
- The Controller of an Entity holds and controls States, Collections, .. for that Entity.
144
- These Agile Sub Instances might get modified by [ actions] ( #📝-.action.ts ) or bound to a Component in the UI-Layer.
145
-
141
+ The Controller manages and represents the Agile Sub Instance like States, Collections, .. for the Entity.
142
+ These Agile Sub Instances might get modified by the [ action.ts] ( #📝-.action.ts ) or bound to a Component in the UI-Layer.
146
143
``` ts title="todo.controller.ts in 📁todo"
147
144
import {App } from ' ../../app' ;
148
145
import {TodoInterface } from ' ./todo.interface' ;
@@ -165,11 +162,11 @@ The `interface` section can be ignored by non [Typescript](https://www.typescrip
165
162
166
163
:::
167
164
168
- If you are a [ Typescript] ( https://www.typescriptlang.org/ ) user, you properly want to create an interface for your entity .
169
- These interfaces belonging to this entity should be defined here.
165
+ If you are a [ Typescript] ( https://www.typescriptlang.org/ ) user, you properly want to create some interfaces for your Entity .
166
+ These interfaces belonging to this Entity should be defined here.
170
167
171
168
** For instance** <br />
172
- In case of the TODO-Entity, it contains a _ TodoInterface _ .
169
+ In case of the TODO-Entity, it contains the ` TodoInterface ` .
173
170
174
171
``` ts title="todo.interface.ts in 📁todo"
175
172
export interface TodoInterface {
@@ -182,11 +179,10 @@ export interface TodoInterface {
182
179
183
180
### 📝 .route.ts
184
181
185
- To communicate to our server, we have to create [ rest calls] ( https://en.wikipedia.org/wiki/Representational_state_transfer ) .
186
- For better maintainability, these rest calls are provided here in function shape
187
- and should only be used in [ actions ] ( #📝-.action.ts ) of the Entity.
182
+ In order to communicate to our server, we have to create [ rest calls] ( https://en.wikipedia.org/wiki/Representational_state_transfer ) .
183
+ For better maintainability, these rest calls are outsourced from the [ action.ts ] ( #-actionts ) and provided by this section in function shape.
184
+ The routes should only be used in the [ action.ts ] ( #-actionts ) of the Entity.
188
185
It's not recommended calling them from outside the corresponding Entity.
189
-
190
186
``` ts title="todo.route.ts in 📁todo"
191
187
import {TodoInterface } from " ./todo.interface" ;
192
188
import api from " ../../api" ;
@@ -202,15 +198,14 @@ export const ADD_TODO = async (payload: AddTodoPayloadInterface): Promise<TodoIn
202
198
}
203
199
204
200
// ..
205
-
206
201
```
207
202
208
203
## 📝 app.ts
209
204
210
- In this file, we create our main ` Agile Instance ` and configure it to meet our needs.
211
- For example, we determine here with which UI framework AgileTs works together.
212
- States, Collections, etc. then can be created with help of this Instance .
213
- ** It's not recommended having multiple ` Agile Instances ` in one Application !!**
205
+ In the ` app ` file, we create our main ` Agile Instance ` and configure it to meet our needs.
206
+ For example, we determine here with which UI framework AgileTs should work together.
207
+ States, Collections, etc. can then be created with the help of this instance .
208
+ ** It's not recommended to have multiple ` Agile Instances ` in one application !!**
214
209
215
210
``` ts title="app.ts"
216
211
import {Agile } from " @agile-ts/core" ;
@@ -222,9 +217,8 @@ export const App = new Agile({logJobs: true}).use(reactIntegration);
222
217
## 📝 index.ts
223
218
224
219
Here we export our ` core ` entities so that each entity can be reached without any detours.
225
- For instance, we might import the ` core ` in our UI-Layer.
226
- There we than just import our ` core ` and mutate each entity from it like ` core.todo.addTodo(/* */) ` .
227
-
220
+ In our UI-Layer we than simply import our ` core ` and can mutate entities like the Todo-Entity (` core.todo.addTodo(/* */) ` )
221
+ without further thinking.
228
222
``` ts title="index.ts"
229
223
import todo from " ./controllers/todo" ;
230
224
import user from " ./controllers/user" ;
@@ -235,7 +229,7 @@ const core = {
235
229
user: user ,
236
230
};
237
231
238
- // For better debugging you might want our core global (Don't do that in PRODUCTION!!)
232
+ // For better debugging, you might want our core global (Don't do that in PRODUCTION!!)
239
233
globalBind (" __core__" , core );
240
234
241
235
export default core ;
0 commit comments