Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 67bb8f9

Browse files
committed
optimized docs
1 parent 16cd174 commit 67bb8f9

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

docs/packages/core/features/collection/Introduction.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ MY_COLLECTION.createGroup("groupName", [/*initial Items*/]);
6464
```
6565
We might use a Group, if we want to have an array of 'Today Todos' from
6666
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.
6773

6874
In our Collection we are able to create as many Groups as we want, and the Collection won't lose
6975
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' }, ...]'
9197

9298
## 🔮 [Selector](./selector/Introduction.md)
9399

94-
Selectors allow us to _select_ a specific Item from our Collection.
100+
Selectors allow us to _select_ one specific Item from our Collection.
95101
```ts
96102
MY_COLLECTION.createSelector("selectorName", /*to select Item Key*/);
97103
```
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/>
100109

101110
A Selector is also able to select a not existing Item, then it holds
102111
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.
104113
```ts
105114
MY_SELECTOR.select("notExistingItem");
106115
MY_SELECTOR.value; // Returns 'undefined' until it the Item got added to the Collection
107116
```
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.
109118
```ts
110119
MY_SELECTOR.undo(); // Undo latest change
111120
```
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
113122
selected Item in the Collection. To do that we have to modify the Item directly.
114123
```ts
115124
MY_SELECTOR.item.set({id: 1, name: "jeff"});
@@ -119,18 +128,18 @@ MY_SELECTOR.item.set({id: 1, name: "jeff"});
119128

120129
There are two ways to configure our Collection:
121130

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.
123132
Here we are limited in the creation of Groups and Selectors,
124133
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.
126135
```ts
127136
const Collection = App.createCollection({
128137
key: 'dummyCollection',
129138
group: ["dummyGroup"]
130139
})
131140
```
132141

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.
134143
But this time the object has to be returned by a function, which has the collection as its only parameter.
135144
By approaching the collection, we are able to create Groups and Selectors on our own, which
136145
gives us more freedom in configuring these Instances.
@@ -143,8 +152,8 @@ There are two ways to configure our Collection:
143152
}))
144153
```
145154

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.
148157
```ts
149158
export interface CreateCollectionConfigInterface<DataType = DefaultItem> {
150159
groups?: { [key: string]: Group<any> } | string[];

0 commit comments

Comments
 (0)