@@ -103,7 +103,7 @@ To get a better understanding of how to use a State, we should just try it out.
103
103
Therefore, we have created a Live Example, where we can see a [ State] ( ../packages/core/features/state/Introduction.md ) in action.
104
104
The sample project we'll look at is a small counter that lets us increase a number as we click the 'Update State' button.
105
105
It may not be very exciting, but it shows all the essential pieces of a React + AgileTs application in action.
106
- After we have tried the live example a bit, we recommend giving the [ Important Code Snippets] ( #-important-code-snippets-e1 ) a look
106
+ After we have tried the live example a bit, we recommend giving the [ Important Code Snippets] ( #-important-code-snippets-e1 ) below a look
107
107
to better understand what the different parts exactly do.
108
108
In case you have any further questions, don't mind joining our [ Community Discord] ( https://discord.gg/T9GzreAwPH ) .
109
109
``` tsx live
@@ -194,14 +194,15 @@ Each data we collect **needs a unique primary key** like an `id`, to be properly
194
194
TODOS .collect ({id: " id2" , todo: " Try AgileTs" });
195
195
```
196
196
In the above code snippet, 'id2' at the primary key property ` id ` is the unique primary key.
197
- The collected data will be automatically transformed into an extension of the State Class called Item, which has the collected data as ` value ` ,
198
- so in our case '{id: "id2", todo: "Try AgileTs"}'.
197
+ Every collected data will be automatically transformed into an extension of the State Class called ` Item ` .
198
+ Such an Item has the collected data as ` value ` , so in the above example that would be '{id: "id2", todo: "Try AgileTs"}'.
199
199
A so-called Item has the same functionalities as normal States.
200
200
``` ts
201
201
MY_COLLECTION .getItem (' id2' ).patch ({todo: " Clean Bathroom" });
202
202
```
203
- Besides Items, a Collection consists primarily of Groups, which allows us to split the Collection into multiple individual sections without
204
- losing redundant behavior. By default, each Item will be added to the ` default ` Group, representing the default Collection pattern.
203
+ Besides Items, a Collection consists primarily of Groups.
204
+ A Group allows us to split a Collection into multiple individual sections without
205
+ losing any redundant behavior. By default, each Item will be added to the ` default ` Group, representing the default Collection pattern.
205
206
Keep in mind, that a Group doesn't store the Item itself. It only holds an array of ` primaryKeys ` like a keymap of the data it represents.
206
207
``` ts
207
208
const USER_TODOS = TODOS .createGroup (" user-todos" , [" id1" , " id2" ]); // TODOS of a specifc User
@@ -211,7 +212,8 @@ const TODAY_TODOS = TODOS.createGroup("today-todos", ["id3", "id2", "id5"]); //
211
212
### 🔴 Live Example [ e2]
212
213
213
214
In this Live Example, we can see a simple [ Collection] ( ../packages/core/features/collection/Introduction.md ) in action.
214
- The sample project we'll look at is a small todo list that lets us create todos with the help of text input and remove them with a button below each todo item.
215
+ The sample project we'll look at is a small todo list that lets us create todos with the help of text input
216
+ and remove them with a button below each todo item.
215
217
In case you have any further questions, don't mind joining our [ Community Discord] ( https://discord.gg/T9GzreAwPH ) .
216
218
``` tsx live
217
219
// Let's start by creating our Agile Instance
@@ -275,14 +277,15 @@ const MY_FIRST_COLLECTION = App.createCollection({
275
277
To create our first Collection, we need the previously instantiated Instance of AgileTs.
276
278
Then we can bring our first Collection to life,
277
279
which got the initial Item ` {id: 1, name: "Clean Bathroom"} ` .
278
- Besides the creation, we store the Collection in the ` localStorage ` with the help of the ` persist() ` function.
280
+ Besides the creation, we store the Collection permanently in the ` localStorage ` with the help of the ` persist() ` function.
281
+ So if you refresh the page your modifications to the todo list shouldn't be lost.
279
282
280
283
``` ts
281
284
const myFirstCollection = useAgile (MY_FIRST_COLLECTION );
282
285
```
283
286
Here we use the [ ` useAgile ` ] ( ../packages/react/features/Hooks.md#useagile ) React Hook
284
287
to bind our Collection to the React Component.
285
- In the case of a Collection, it returns the ` default ` Group ` value ` in array shape.
288
+ When passing a Collection, ` useAgile ` returns the ` default ` Group ` value ` in array shape.
286
289
In our case, something like:
287
290
``` ts
288
291
[
@@ -295,14 +298,15 @@ In our case, something like:
295
298
MY_FIRST_COLLECTION .collect ({id: generateId (), name: currentInput });
296
299
```
297
300
In order to add new Data to the Collection, we can use the ` collect() ` function.
298
- We simply add the _ currentInput_ with a random ` id ` as primaryKey.
301
+ In the example we simply add the _ currentInput_ with a random ` id ` as primaryKey to the Collection .
299
302
300
303
``` ts
301
304
TODOS .remove (value .id ).everywhere ();
302
305
```
303
306
In case we have done a todo, of course, we want to remove it.
304
307
The ` remove() ` function helps us to reach this goal.
305
- The ` everywhere() ` tag means that the Item will be removed from the whole Collection.
308
+ The ` everywhere() ` tag means that the Item will be removed from the whole Collection
309
+ and not just from a Group.
306
310
307
311
## 🔍 Next Steps
308
312
0 commit comments