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

Commit 06221c8

Browse files
authored
Merge pull request #18 from agile-ts/develop
Develop
2 parents 378badb + 900d771 commit 06221c8

File tree

9 files changed

+168
-44
lines changed

9 files changed

+168
-44
lines changed

docs/other/DocSearch.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
id: interfaces
3+
title: Interfaces
4+
sidebar_label: Interfaces
5+
slug: /docsearch
6+
---
7+
8+
Hello `docsearch` Team,
9+
10+
As you can see I am the maintainer of this documentation
11+
and have the rights to edit it ^^
12+
13+
With best regards
14+
15+
BennoDev

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

+87-30
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ WIP docs!
1212
:::
1313

1414
A Collection holds a set of Information that we need to remember at a later point in time.
15-
It is designed for arrays of data objects following the same structure.
16-
Be aware that each collected Data needs an **unique primaryKey** to properly identify it later.
15+
It is designed for arrays of data objects following the same pattern.
16+
Be aware that each collected Data needs an **unique primaryKey** to get properly identified later.
1717
We instantiate a Collection with help of an [Agile Instance](../agile-instance/Introduction.md) here called `App`.
1818
By doing this the Collection gets automatically bound to the Agile Instance it was created from.
1919
```ts
@@ -25,11 +25,11 @@ but there we have to pass the `Agile Instance`, to which the Collection should g
2525
const MY_COLLECTION = new Collection(App);
2626
```
2727
Both instantiations lead to the same result, but we recommend using the former way.
28-
After we have successfully created our Collection, we can dynamically manipulate and work with it.
28+
After we have successfully created our Collection, we can work with it dynamically and easily.
2929
```ts
3030
MY_COLLECTION.collect({id: 1, name: "jeff"}); // Add Item to Collection
31-
MY_COLLECTION.remove(1).everywhere(); // Remove Item from everywhere
32-
MY_COLLECTION.persist(); // Persists Collection Value into the Storage
31+
MY_COLLECTION.remove(1).everywhere(); // Remove Item from Collection
32+
MY_COLLECTION.persist(); // Persists Collection Value into a Storage
3333
```
3434
Most methods we use to modify, mutate and access the Collection are chainable.
3535
```ts
@@ -38,36 +38,48 @@ MY_COLLECTION.collect({id: 1, name: "jeff"}).persist().removeGroup('myGroup').re
3838

3939
## 🔹 Item
4040

41-
Each Data we have added to the Collection, like with the `collect` method,
42-
gets applied to an Item and stored as such in our Collection.
41+
Each Data Object we add to our Collection, for example with the `collect` method,
42+
gets transformed to an Item. This Item than gets stored in our Collection.
43+
We can simply access each Item with the `getItem` method and the correct primary Key.
4344
```ts
4445
MY_COLLECTION.getItem(/* primary Key */); // Returns Item at the primary Key
4546
```
46-
An Item is an extension of the State Class and offers the same powerful features.
47+
The cool thing about Items is, they are an extension of the `State Class`.
48+
This means that they have the same powerful tools like a State.
4749
```ts
48-
const myItem = MY_COLLECTION.getItem(1);
50+
MY_COLLECTION.collect({id: 1, name: "jeff"}); // Collect Data
51+
const myItem = MY_COLLECTION.getItem(1); // Returns Item at primaryKey '1'
52+
myItem.value; // Returns '{id: 1, name: "jeff"}'
4953
myItem.patch({name: "frank"}); // Update property 'name' in Item
54+
myItem.undo(); // Undo latest change
5055
```
5156

5257
## 👨‍👧‍👦 [Group](./group/Introduction.md)
5358

5459
Often applications need to categorize and preserve ordering of structured data and
55-
in AgileTs Groups are the cleanest way to reach this goal. They allow us to
60+
in AgileTs Groups are the right way to reach this goal. They allow us to
5661
cluster together data from a Collection as an array of primary Keys.
62+
```ts
63+
MY_COLLECTION.createGroup("groupName", [/*initial Items*/]);
64+
```
5765
We might use a Group, if we want to have an array of 'Today Todos' from
5866
a Todo Collection or Posts that belong to the logged-in User from the Post Collection.
5967
```ts
60-
MY_COLLECTION.createGroup("groupName", [/*initial Items*/]);
68+
USERS.collect(user);
69+
POSTS.collect(user.posts, user.id);
6170
```
62-
We are able to create as many Groups as we want, and the Collection won't lose
63-
its redundant behaviour, since the Items are still stored in the Collection, and
64-
the Groups are only like an interface to it.
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.
73+
74+
In our Collection we are able to create as many Groups as we want, and the Collection won't lose
75+
its redundant behaviour. This is due to the fact, that each Item gets stored in the Collection itself and not in the Group.
76+
You can imagine a Group like an interface to the Collection Data.
6577
```ts
6678
MY_COLLECTION.createGroup("group1", [1, 2, 3]);
6779
MY_COLLECTION.createGroup("group2", [2, 5, 8]);
6880
MY_COLLECTION.createGroup("group5000", [1, 10, 500, 5]);
6981
```
70-
A Group is an extension of the State Class and offers the same powerful features.
82+
Also, a Group is an extension of the `State Class` and offers the same powerful features.
7183
```ts
7284
MY_STATE.undo(); // Undo latest change
7385
MY_GROUP.reset(); // Reset Group to its intial Value
@@ -77,25 +89,36 @@ But be aware that the `value` might not be the output you expect.
7789
```ts
7890
MY_GROUP.value; // Returns '[8, 5, 30, 1]'
7991
```
80-
It holds the primary Keys of the Items the Group represent.
81-
To get the right value to the primary Keys just use `output` property.
92+
Because this property doesn't hold the Item Values, it contains the primary Keys the Group represents.
93+
To get the Item Value to each primary Keys, just use the `output` property.
8294
```ts
8395
MY_GROUP.output; // Returns '[{ id: 8, name: 'jeff' }, ...]'
8496
```
8597

8698
## 🔮 [Selector](./selector/Introduction.md)
8799

88-
Selectors allow us to _select_ an Item from a Collection.
89-
We might use the Selector, if we want to select a 'current User' from our User Collection or
90-
the 'current viewing Post' from our Post Collection.
100+
Selectors allow us to _select_ one specific Item from our Collection.
91101
```ts
92-
MY_COLLECTION.createGroup("selectorName", /*to select Item Key*/);
102+
MY_COLLECTION.createSelector("selectorName", /*to select Item Key*/);
93103
```
94-
A Selector is an extension of the State Class and offers the same powerful features.
104+
We might use the Selector, if we want to select the 'current logged-in User' from our User Collection.
95105
```ts
96-
MY_STATE.undo(); // Undo latest change
106+
USERS.select(/* current logged-in userId */);
97107
```
98-
But be aware that by mutating the Selector we won't modify the
108+
<br/>
109+
110+
A Selector is also able to select a not existing Item, then it holds
111+
a reference to this Item. But be aware that the Value of the Selector is
112+
`undefined` during this period of time, since AgileTs doesn't know your desired Item.
113+
```ts
114+
MY_SELECTOR.select("notExistingItem");
115+
MY_SELECTOR.value; // Returns 'undefined' until it the Item got added to the Collection
116+
```
117+
A Selector is an extension of the State Class too and offers the same powerful features.
118+
```ts
119+
MY_SELECTOR.undo(); // Undo latest change
120+
```
121+
But be aware that by mutating the Selector Value we won't modify the
99122
selected Item in the Collection. To do that we have to modify the Item directly.
100123
```ts
101124
MY_SELECTOR.item.set({id: 1, name: "jeff"});
@@ -105,18 +128,18 @@ MY_SELECTOR.item.set({id: 1, name: "jeff"});
105128

106129
There are two ways to configure our Collection:
107130

108-
- 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.
109132
Here we are limited in the creation of Groups and Selectors,
110133
because we can't create them on our own. The Collection takes care of it instead,
111-
which limits us in configuring of these Instances.
134+
which limits us in configuring these Instances.
112135
```ts
113136
const Collection = App.createCollection({
114137
key: 'dummyCollection',
115138
group: ["dummyGroup"]
116139
})
117140
```
118141

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

132-
Here is a Typescript Interface for quick reference, however
133-
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.
134157
```ts
135158
export interface CreateCollectionConfigInterface<DataType = DefaultItem> {
136159
groups?: { [key: string]: Group<any> } | string[];
@@ -142,6 +165,39 @@ export interface CreateCollectionConfigInterface<DataType = DefaultItem> {
142165
}
143166
```
144167

168+
### `groups`
169+
Here we define the initial [Groups](#groups) of our Collection.
170+
We have two options to add them.
171+
The first way is to just pass an Array of Group Names, than
172+
AgileTs creates these Groups for us.
173+
```ts
174+
const MY_COLLECTION = App.createCollection({
175+
groups: ["myGroup1", "myGroup2"]
176+
});
177+
```
178+
But if we want to add some initial Items to the Groups we have to go the
179+
`function` config way.
180+
```ts
181+
const MY_COLLECTION = App.createCollection((collection) => ({
182+
key: 'dummyCollection',
183+
group: {
184+
myGroup1: collection.Group(["item1", "item2"]),
185+
myGroup2: collection.Group(["item5", "item2", "item6"])
186+
}
187+
}))
188+
```
189+
190+
### `key`
191+
The Key/Name is an optional property, that gets used to identify our Collection.
192+
This is pretty useful during debug sessions or if we persist our Collection,
193+
where it automatically uses the `key` as persist key.
194+
We recommend giving each Collection an unique `key`. It has only advantages.
195+
```ts
196+
const MY_COLLECTION = App.createCollection({
197+
key: "myKey"
198+
});
199+
```
200+
145201

146202
## 🟦 Typescript
147203

@@ -154,4 +210,5 @@ interface UserInterface {
154210
const MY_COLLECTION = App.createState<UserInterface>();
155211
MY_COLLECTION.collect({id: "invalidType", animal: "Lion"}); // Error
156212
MY_COLLECTION.collect({id: 1, name: "hans"}); // Success
157-
```
213+
```
214+
This type defines the Value Type of the Collection Items.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: properties
3+
title: Properties
4+
sidebar_label: Properties
5+
slug: /core/collection/properties
6+
---
7+
8+
:::warning
9+
10+
WIP docs!
11+
12+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: properties
3+
title: Properties
4+
sidebar_label: Properties
5+
slug: /core/collection/group/properties
6+
---
7+
8+
:::warning
9+
10+
WIP docs!
11+
12+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: properties
3+
title: Properties
4+
sidebar_label: Properties
5+
slug: /core/collection/selector/properties
6+
---
7+
8+
:::warning
9+
10+
WIP docs!
11+
12+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: properties
3+
title: Properties
4+
sidebar_label: Properties
5+
slug: /core/computed/properties
6+
---
7+
8+
:::warning
9+
10+
WIP docs!
11+
12+
:::

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ By doing this the State gets automatically bound to the Agile Instance it was cr
1919
const MY_STATE = App.createState("Hello World");
2020
```
2121
There is also a way to use the plain `State Class`,
22-
but there we have to pass the `Agile Instance`, to which the State should get bound, beside the initial Value and config.
22+
but there we have to pass the `Agile Instance`, to which the State should get bound, beside the initial Value.
2323
```ts
2424
const MY_STATE = new State(App, "Hello World");
2525
```
2626
Both instantiations lead to the same result, but we recommend using the former way.
27-
After we have successfully created our State, we can dynamically manipulate and work with it.
27+
After we have successfully created our State, we can work with it dynamically and easily.
2828
```ts
2929
MY_STATE.set("Hello There"); // Set State Value to "Hello There"
3030
MY_STATE.undo(); // Undo latest change
3131
MY_STATE.is("Hello World"); // Check if State has a specific Value
32-
MY_STATE.persist(); // Persist State Value into Storage
32+
MY_STATE.persist(); // Persist State Value into a Storage
3333
```
3434
Most methods we use to modify, mutate and access the State are chainable.
3535
```ts
@@ -38,7 +38,7 @@ MY_STATE.undo().set("Hello Hell").watch(() => {}).reset().invert().persist().typ
3838

3939
## 📭 Props
4040

41-
`State` takes, beside the initial value an optional configuration object.
41+
A `State` takes, beside the initial value an optional configuration object.
4242
```ts
4343
const MY_STATE = App.createState("myInitialValue", {
4444
key: "myKey",
@@ -56,8 +56,8 @@ export interface StateConfigInterface {
5656
```
5757

5858
### `key`
59-
The Key/Name is an optional property, that gets used to identify a State.
60-
This is pretty useful during debug sessions or if we persist a State,
59+
The Key/Name is an optional property, that gets used to identify our State.
60+
This is pretty useful during debug sessions or if we persist our State,
6161
where it automatically uses the `key` as persist key.
6262
We recommend giving each State an unique `key`. It as only advantages.
6363
```ts
@@ -74,9 +74,9 @@ Gets mostly used internal and has properly no use for you.
7474

7575
:::
7676

77-
`Dependents` is used to detect States, that depend on this State.
77+
Here we define which States depend on our State.
7878
This means if our State gets mutated and ingested into the Runtime,
79-
the depending State gets also ingested into the Runtime.
79+
the depending States gets also ingested into the Runtime.
8080
```ts
8181
const MY_STATE = App.createState("myInitialValue", {
8282
dependents: [MY_STATE_2]
@@ -91,8 +91,8 @@ Gets mostly used internal and has properly no use for you.
9191

9292
:::
9393

94-
With `isPlaceholder` we define, that this State is a placeholder.
95-
Mostly a State is a Placeholder if we want to hold a reference to a State that hasn't been instantiated yet.
94+
With `isPlaceholder` we define, that our State is a placeholder.
95+
Mostly a State is a Placeholder if we want to hold a reference to it, because hasn't been instantiated yet.
9696
```ts
9797
const MY_STATE = App.createState("myInitialValue", {
9898
isPlaceholder: true
@@ -112,4 +112,4 @@ Javascript users can also get rudimentary typesafe, with the `type` function.
112112
```ts
113113
MY_STATE.type(String); // Now State only accept State Values
114114
```
115-
Be aware that the `type` function currently only supports primitive types.
115+
Be aware that the `type` function currently only supports primitive types.

docs/quick_start/React.md

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ MY_FIRST_STATE.set(`Hello World ${++helloWorldCount}`);
149149
To bring some life into our small Application we update the State with the `set` function
150150
in which we just pass our desired new value.
151151

152+
To find out more about States, checkout our [State](../packages/core/features/state/Introduction.md) docs.
153+
152154
<br />
153155

154156
---
@@ -253,6 +255,7 @@ Be aware that hooks can only be used in React Components!
253255
To add new Data to our Collection, we cann use the `collect` function.
254256
In this case we add the _currentInput_ to our Collection, with a random Id as primaryKey.
255257

258+
To find out more about Collections, checkout our [Collection](../packages/core/features/collection/Introduction.md) docs.
256259

257260
## 🔍 More
258261

sidebars.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,23 @@ module.exports = {
4242
items: [
4343
"packages/core/features/collection/introduction",
4444
"packages/core/features/collection/methods",
45+
"packages/core/features/collection/properties",
4546
{
4647
type: 'category',
4748
label: 'Group',
48-
items: ["packages/core/features/collection/group/introduction", "packages/core/features/collection/group/methods"]
49+
items: ["packages/core/features/collection/group/introduction", "packages/core/features/collection/group/methods", "packages/core/features/collection/group/properties"]
4950
},
5051
{
5152
type: 'category',
5253
label: 'Selector',
53-
items: ["packages/core/features/collection/selector/introduction", "packages/core/features/collection/selector/methods"]
54+
items: ["packages/core/features/collection/selector/introduction", "packages/core/features/collection/selector/methods", "packages/core/features/collection/selector/properties"]
5455
},
5556
]
5657
},
5758
{
5859
type: 'category',
5960
label: 'Computed',
60-
items: ["packages/core/features/computed/introduction", "packages/core/features/computed/methods"]
61+
items: ["packages/core/features/computed/introduction", "packages/core/features/computed/methods", "packages/core/features/computed/properties"]
6162
},
6263
{
6364
type: 'category',

0 commit comments

Comments
 (0)