@@ -64,6 +64,12 @@ MY_COLLECTION.createGroup("groupName", [/*initial Items*/]);
64
64
```
65
65
We might use a Group, if we want to have an array of 'Today Todos' from
66
66
a Todo Collection or Posts that belong to the logged-in User from the Post Collection.
67
+ ``` ts
68
+ USERS .collect (user );
69
+ POSTS .collect (user .posts , user .id );
70
+ ```
71
+ Here we have two Collections, one for users and another for posts.
72
+ We can collect posts specific to a user and group them automatically by the user's id.
67
73
68
74
In our Collection we are able to create as many Groups as we want, and the Collection won't lose
69
75
its redundant behaviour. This is due to the fact, that each Item gets stored in the Collection itself and not in the Group.
@@ -91,25 +97,28 @@ MY_GROUP.output; // Returns '[{ id: 8, name: 'jeff' }, ...]'
91
97
92
98
## 🔮 [ Selector] ( ./selector/Introduction.md )
93
99
94
- Selectors allow us to _ select_ a specific Item from our Collection.
100
+ Selectors allow us to _ select_ one specific Item from our Collection.
95
101
``` ts
96
102
MY_COLLECTION .createSelector (" selectorName" , /* to select Item Key*/ );
97
103
```
98
- We might use the Selector, if we want to select a 'current User' from our User Collection or
99
- the 'current viewing Post' from our Post Collection.
104
+ We might use the Selector, if we want to select the 'current logged-in User' from our User Collection.
105
+ ``` ts
106
+ USERS .select (/* current logged-in userId */ );
107
+ ```
108
+ <br />
100
109
101
110
A Selector is also able to select a not existing Item, then it holds
102
111
a reference to this Item. But be aware that the Value of the Selector is
103
- ` undefined ` during this period of time, since we do not know your desired Item.
112
+ ` undefined ` during this period of time, since AgileTs doesn't know your desired Item.
104
113
``` ts
105
114
MY_SELECTOR .select (" notExistingItem" );
106
115
MY_SELECTOR .value ; // Returns 'undefined' until it the Item got added to the Collection
107
116
```
108
- Beside the Group, a Selector is also an extension of the State Class and offers the same powerful features.
117
+ A Selector is an extension of the State Class too and offers the same powerful features.
109
118
``` ts
110
119
MY_SELECTOR .undo (); // Undo latest change
111
120
```
112
- But be aware that by mutating the Selector we won't modify the
121
+ But be aware that by mutating the Selector Value we won't modify the
113
122
selected Item in the Collection. To do that we have to modify the Item directly.
114
123
``` ts
115
124
MY_SELECTOR .item .set ({id: 1 , name: " jeff" });
@@ -119,18 +128,18 @@ MY_SELECTOR.item.set({id: 1, name: "jeff"});
119
128
120
129
There are two ways to configure our Collection:
121
130
122
- - 1 . The plain _ object_ way, where we configure everything in an object.
131
+ - ** 1. ** The plain _ object_ way, where we configure everything in an object.
123
132
Here we are limited in the creation of Groups and Selectors,
124
133
because we can't create them on our own. The Collection takes care of it instead,
125
- which limits us in configuring of these Instances.
134
+ which limits us in configuring these Instances.
126
135
``` ts
127
136
const Collection = App .createCollection ({
128
137
key: ' dummyCollection' ,
129
138
group: [" dummyGroup" ]
130
139
})
131
140
```
132
141
133
- - 2. The _function_ way , where we configure everything in an object too .
142
+ - ** 2. ** The _function_ way , where we configure everything in an object too .
134
143
But this time the object has to be returned by a function , which has the collection as its only parameter.
135
144
By approaching the collection, we are able to create Groups and Selectors on our own, which
136
145
gives us more freedom in configuring these Instances.
@@ -143,8 +152,8 @@ There are two ways to configure our Collection:
143
152
}))
144
153
```
145
154
146
- Here is a Typescript Interface for quick reference , however
147
- each property will be explained in more detail below .
155
+ Here is a Typescript Interface of the configuration Object for quick reference ,
156
+ however each property will be explained in more detail below .
148
157
` ` ` ts
149
158
export interface CreateCollectionConfigInterface<DataType = DefaultItem> {
150
159
groups?: { [key: string]: Group<any> } | string[];
0 commit comments