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

Commit 99ab7ae

Browse files
committed
created Persisting Data docs
1 parent b161c86 commit 99ab7ae

File tree

15 files changed

+167
-183
lines changed

15 files changed

+167
-183
lines changed

docs/main/Introduction.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ Without any context this Section might be useless to you. As the name suggests,
162162
AgileTs, which are outsourced for a better overview. You might get redirected to parts of the Interface Section from
163163
other documentation sections. Often to learn some more about specific properties of an interface.
164164

165+
## 🤓 Glossary
166+
167+
In these docs, we will refer to our classes with a capital first letter.
168+
For example, when you see 'state' we are referring to the programming concept `state`,
169+
but when you see 'State' we are referring to our [State](../packages/core/features/state/Introduction.md) class.
170+
171+
### `Agile Sub Instance`
172+
Instances that hold a reference to the [`Agile Instance`](../packages/core/features/agile-instance/Introduction.md)
173+
and depend on its functionalities.
174+
- [States](../packages/core/features/state/Introduction.md)
175+
- [Collections](../packages/core/features/collection/Introduction.md)
176+
- [Groups](../packages/core/features/collection/group/Introduction.md)
177+
- [Selectors](../packages/core/features/collection/selector/Introduction.md)
178+
- [Computed States](../packages/core/features/computed/Introduction.md)
179+
165180
## 💬 What others say
166181

167182
Actually, nothing, yet. If you want to be the first one, don't mind tweeting whatever you think about AgileTs.

docs/main/StyleGuide.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ We use the `store.ts` file of a simple TODO application to illustrate how it can
4646

4747
### 📝 store.ts
4848

49-
In the `store.ts` file, we instantiate the Agile Instance (`Agile`) and define all Agile Sub Instances (`MY_TODOS`).
49+
In the `store.ts` file, we instantiate the Agile Instance (`Agile`) and define all [Agile Sub Instances](../main/Introduction.md#agile-sub-instance) (`MY_TODOS`).
5050
In addition, all actions (`updateTodo()`, `toogleTodo()`, ..) and if you are using Typescript, interfaces (`TodoInterface`) are located here.
5151
If you are wondering why we write AgileTs States uppercase. Well, it has a simple advantage.
5252
We can easily differentiate between global and local States in our Components.
@@ -237,8 +237,8 @@ export const addTodo = async (userId: string, description: string): Promise<void
237237

238238
### 📝 .controller.ts
239239

240-
The `controller.ts` manages and represents the Agile Sub Instance (like States, Collections, ..) for an Entity.
241-
These Agile Sub Instances might get modified by the actions in the [action.ts](#📝-.action.ts) file or bound to Components in the UI-Layer.
240+
The `controller.ts` manages and represents the [Agile Sub Instances](../main/Introduction.md#agile-sub-instance) (like States, Collections, ..) for an Entity.
241+
These [Agile Sub Instances](../main/Introduction.md#agile-sub-instance) might get modified by the actions in the [action.ts](#📝-.action.ts) file or bound to Components in the UI-Layer.
242242
If you are wondering why we write AgileTs States uppercase. Well, it has a simple advantage.
243243
We can easily differentiate between global and local States in our Components.
244244
```ts title="todo.controller.ts in 📁todo"

docs/packages/core/Installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ The `core` package can be installed over [npm](https://www.npmjs.com/).
1010
```bash npm2yarn
1111
npm install @agile-ts/core
1212
```
13-
If you prefer following a Quick Start Guide,
14-
which guides you through the process of installing AgileTs in a specific UI-Framework. 🚀
13+
In case you prefer following a Quick Start Guide,
14+
which guides you through the process of installing AgileTs in a specific UI-Framework:
1515
- [React/React-Native](../../quick_start/React.md)
1616
- [Vue](../../quick_start/Vue.md)
1717
- [Angular](../../quick_start/Angular.md)

docs/packages/core/Introduction.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Therefore, it contains the main Instance of AgileTs, called [`Agile Class`](./fe
2727
const App = new Agile();
2828
```
2929
In summary the main tasks of the `Agile Class` are to:
30-
- queuing `Agile Sub Instance` changes in the `runtime` and preventing race conditions
30+
- queuing [`Agile Sub Instance`](../../main/Introduction.md#agile-sub-instance) changes in the `runtime` and preventing race conditions
3131
- provide configuration object
3232
- update/rerender subscribed Components through Integrations like the [React Integration](../react/Introduction.md)
3333
- Integrating with persistent [Storage](./features/storage/Introduction.md)
@@ -59,7 +59,7 @@ MY_COLLECTION.remove(1).everywhere(); // Remove Data at primary Key '1' from Col
5959
```
6060

6161
### 🤖 [Computed](./features/state/Introduction.md)
62-
A Computed is an extension of the `State Class` and automatically computes its value depending on other Agile Sub Instances like States, Collections, ..
62+
A Computed is an extension of the `State Class` and automatically computes its value depending on other [Agile Sub Instances](../../main/Introduction.md#agile-sub-instance) like States, Collections, ..
6363
```ts
6464
const MY_COMPUTED = App.createComputed(() => (MY_STATE_1.value + MY_STATE_2.value));
6565
```
@@ -85,4 +85,5 @@ A Computed is an extension of the `State Class` and automatically computes its v
8585
- [Properties](./features/computed/Properties.md)
8686
- [Methods](./features/computed/Methods.md)
8787
- [Storage](./features/storage/Introduction.md)
88+
- [Persisting Data](./features/storage/PersistingData.md)
8889
- [Integration](./features/integration/Introduction.md)

docs/packages/core/features/agile-instance/Introduction.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ The `Agile Class` is the main Instance of AgileTs and should be unique to our ap
99
```ts
1010
const App = new Agile();
1111
```
12-
It can be seen as the interface to any Storage or the Frameworks AgileTs is implemented in.
13-
In addition, it manages the changes of `Agile Sub Instances` to prevent race conditions.
12+
It can be seen as an Interface to any Storage or the Frameworks AgileTs is implemented in.
13+
In addition, it manages the changes of [`Agile Sub Instances`](../../../../main/Introduction.md#agile-sub-instance) to prevent race conditions.
1414
Each `Agile Sub Instance` (ASI) holds a reference to the `Agile Class` and depends on its functionalities.
15-
Furthermore, ASI's are created with the help of an instantiated `Agile Class`.
16-
For reference, here are some `Agile Sub Instances` (ASI) created with an `Agile Instance` called `App`:
15+
Furthermore, ASI's can be created with the help of an instantiated `Agile Class`.
16+
For reference, here are some `Agile Sub Instances` (ASI) created with an instantiated `Agile Instance` called `App`:
1717

1818
- [State](../state/Introduction.md)
1919
```ts
@@ -29,7 +29,7 @@ For reference, here are some `Agile Sub Instances` (ASI) created with an `Agile
2929
```
3030

3131
In summary the main tasks of the `Agile Class` are to:
32-
- queuing `Agile Sub Instance` changes in the `runtime` and preventing race conditions
32+
- queuing [`Agile Sub Instance`](../../../../main/Introduction.md#agile-sub-instance) changes in the `runtime` and preventing race conditions
3333
- provide configuration object
3434
- update/rerender subscribed Components through Integrations like the [React Integration](../../../react/Introduction.md)
3535
- Integrating with persistent [Storage](../storage/Introduction.md)
@@ -80,7 +80,7 @@ To find out more about possible configuration options, checkout the [CreateLogge
8080

8181
#### `localStorage`
8282
Whether AgileTs should create an interface to the [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp) and set it as default Storage.
83-
Each Agile Sub Instance we persist (`.persist()`), will then be stored in the `localStorage` by default.
83+
Each [Agile Sub Instance](../../../../main/Introduction.md#agile-sub-instance) we persist (`.persist()`), will then be stored in the `localStorage` by default.
8484
```ts
8585
new Agile({
8686
localStorage: false // default true

docs/packages/core/features/agile-instance/Properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Here are valuable properties of the `Agile Class` listed.
1313

1414
## `logger`
1515

16-
The `logger` is a static property of the `Agile Class`,
17-
used internally to log warnings, errors, debug messages, .. to the console.
16+
The `logger` is a static property of the `Agile Class`.
17+
It is used internally to log warnings, errors, debug messages, .. to the console.
1818
```ts
1919
Agile.logger.warn("This is a Warning");
2020
Agile.logger.log("This is a normal Log");

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

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -989,83 +989,10 @@ All other Instances that refer to the Collection have to be persisted separately
989989
MY_COOL_GROUP.persist();
990990
```
991991

992-
### 💻 Web
993-
In a web environment, it is common to use the [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp) to store values permanently.
994-
AgileTs has set up the Local Storage by default.
995-
```ts {2}
996-
const App = new Agile({
997-
localStorage: true
998-
});
999-
```
1000-
Therefore, we can use the `persist()` method out of the box.
1001-
1002-
### 📱 Mobile
1003-
Since the Local Storage doesn't exist in a mobile environment,
1004-
we have to resort to an alternative, such as the [Async Storage](https://reactnative.dev/docs/asyncstorage).
1005-
AgileTs hasn't set up the Async Storage by default.
1006-
Therefore, we need to create a [Storage](../storage/Introduction.md) Interface representing the Async Storage
1007-
and register it to AgileTs.
1008-
```ts {3-9}
1009-
App.registerStorage(
1010-
App.createStorage({
1011-
key: "AsyncStorage",
1012-
async: true,
1013-
methods: {
1014-
get: AsyncStorage.getItem,
1015-
set: AsyncStorage.setItem,
1016-
remove: AsyncStorage.removeItem,
1017-
},
1018-
}), {default: true} // Tells AgileTs that it is the default Storage
1019-
);
1020-
```
1021-
1022-
### 🔑 Local Storage Key
1023-
Thus AgileTs can access and identify the stored value in the appropriate Storage,
1024-
we have to define a unique `storageKey`.
1025-
There are several ways to provide such required `storageKey` to the `persist()` method.
1026-
1027-
- **1.** Assign a unique key to the Collection itself.
1028-
Because if no key is given to the `persist()` method,
1029-
it takes the Collection key as `storageKey`.
1030-
```ts {2}
1031-
MY_COLLECTION.key = "myCoolKey";
1032-
MY_COLLECTION.persist(); // Success (storageKey = 'myCoolKey')
1033-
```
1034-
- **2.** Pass the `storageKey` directly into the `persist()` method.
1035-
```ts {1}
1036-
MY_COLLECTION.persist("myCoolPassedKey"); // Success (storageKey = 'myCoolPassedKey')
1037-
```
1038-
1039-
If AgileTs couldn't find any fitting `storageKey`,
1040-
it throws an error and doesn't persist the Collection `value`.
1041-
```ts {2}
1042-
MY_COLLECTION.key = undefined;
1043-
MY_COLLECTION.persist(); // Error
1044-
```
992+
### 🤓 Learn more
1045993

1046-
### 💾 `default` Storage
1047-
In AgileTs we can register `multipe` Storages. However only one of these Storages can be the `default` Storage.
1048-
The `default` Storage is used by the `persist()` method whenever no specific Storage is defined.
1049-
```ts {1}
1050-
MY_COLLECTION.persist(); // persist in default Storage
1051-
MY_COLLECTION.persist({
1052-
storageKeys: ["storageA"]
1053-
}); // persist in Storage called 'storageA'
1054-
```
1055-
1056-
### 📝 Multiple Storages
1057-
Sometimes we may store Collections in different Storages.
1058-
For example, _Collection A_ should be stored in _Storage B_, and _Collection B_ should be stored in _Storage A_.
1059-
Then, we can define with `storageKeys` in which specific Storage the Collection `value` should be persisted.
1060-
```ts {2}
1061-
MY_COLLECTION.persist({
1062-
storageKeys: ["myCustomStorage"]
1063-
});
1064-
```
1065-
By default, the Collection will be stored in the [default Storage](#-default-storage).
1066-
```ts
1067-
App.storages.config.defaultStorageKey; // Returns key of current default Storage
1068-
```
994+
If you want to find out more about persisting Instances like Collections,
995+
checkout the [Persisting Data](../storage/PersistingData.md) Section.
1069996

1070997
### 📭 Props
1071998

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const MY_COMPUTED = App.createComputed(() => {
1414
return `My name is '${MY_NAME.value}' and I am ${MY_AGE.value} years old.`;
1515
});
1616
```
17-
A `Computed` will magically track used dependencies (such as Agile Sub Instances like [States](../state/Introduction.md) or [Collections](../collection/Introduction.md))
17+
A `Computed` will magically track used dependencies (such as [Agile Sub Instances](../../../../main/Introduction.md#agile-sub-instance) like [States](../state/Introduction.md) or [Collections](../collection/Introduction.md))
1818
and recomputes when any of its dependencies mutates. For instance, in the above example, it would recompute when the `MY_NAME` value changes from 'jeff' to 'hans'.
1919
```ts
2020
MY_COMPUTED.value; // Returns "My name is 'jeff' and I am 10 years old"
@@ -99,7 +99,7 @@ MY_COMPUTED.value; // Returns "My name is 'jeff' and I am 10 years old."
9999
```
100100
In most cases, it isn't necessary to provide any hard-coded dependency.
101101
However, it might occur that the Computed Class fails to autodetect a particular dependency.
102-
You can check if all dependencies got correctly noticed by giving each used Agile Sub Instance a unique key
102+
You can check if all dependencies got correctly noticed by giving each used [Agile Sub Instance](../../../../main/Introduction.md#agile-sub-instance) a unique key
103103
and reviewing the `deps` array.
104104
```ts
105105
MY_COMPUTED.deps; // Returns '[Observer('myName'), Observer('myAge')]'

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If there is no existing Integration yet, this Section might be interesting for y
1616
:::
1717

1818
The `Integration Class` serves an Interface to UI-Frameworks like [React](https://reactjs.org/).
19-
Its main task is to cause rerender on Components that have subscribed Agile Sub Instances like [States](../state/Introduction.md).
19+
Its main task is to cause rerender on Components that have subscribed A[Agile Sub Instances](../../../../main/Introduction.md#agile-sub-instance) like [States](../state/Introduction.md).
2020
```ts
2121
new Integration({
2222
key: 'myFramework',
@@ -29,7 +29,7 @@ new Integration({
2929
updateMethod: (componentInstance, updatedData) => {
3030
// Will be called on each State value mutation (only in Component based Subscriptions)
3131
// For example, if MY_STATE value mutates from 'jeff' to 'hans'
32-
// Then this method will be called with folowing props:
32+
// Then this method will be called with the following props:
3333
// componentInstance: Component to which the State is subscribed to
3434
// updatedData: Changed data (in our case '{myState: 'hans'}')
3535
//
@@ -93,7 +93,7 @@ App.subController.subscribeWithSubsArray(
9393
}
9494
);
9595
```
96-
This way, we can ensure that each Agile Sub Instance can be mapped into the `updateData` object.
96+
This way, we can ensure that each [Agile Sub Instance](../../../../main/Introduction.md#agile-sub-instance) can be mapped into the `updateData` object.
9797

9898
### `Callback` based
9999

@@ -164,14 +164,15 @@ However, to efficiently use AgileTs in Functional and Class Components,
164164
we had to create ways to simplify the binding of States to UI-Components.
165165
Therefore, we created the `useAgile()` Hook for Functional Components
166166
and the `AgileHOC()` for Class Components.
167-
Below we visually demonstrate the difference of,
167+
In the following examples we visually demonstrate the difference of,
168168
how much easier e.g. the `useAgile()` Hook made the binding of States to Components:
169169
- binding State with `useAgile()`:
170170
```ts title=FunctionalComponent.ts
171171
useAgile(MY_STATE);
172172
```
173173
- binding State manually:
174174
```ts title=FunctionalComponent.ts
175+
// Simple reducer to create a 'rerender' callback
175176
const [, forceRender] = React.useReducer((s) => s + 1, 0);
176177

177178
useEffect(() => {
@@ -259,7 +260,7 @@ new Integration(config);
259260

260261
### `config`
261262

262-
A `Integration` takes a required configuration object as its only parameter.
263+
An `Integration` takes a required configuration object as its only parameter.
263264
```ts
264265
new Integration<typeof React, AgileReactComponent>({
265266
key: 'myFramework',
@@ -350,7 +351,7 @@ Will be called as soon as a State subscribed to a Component (`componentInstance`
350351
new Integration({
351352
updateMethod: (componentInstance, updatedData) => {
352353
// For example, if MY_STATE value mutates from 'jeff' to 'hans'
353-
// Then this method will be called with folowing props:
354+
// Then this method will be called with the following props:
354355
// componentInstance: Component to which the State is subscribed to
355356
// updatedData: Changed data (for instance '{myState: 'hans'}')
356357
}

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

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -527,83 +527,10 @@ Preserves the State `value` in the appropriate local Storage for the current env
527527
MY_STATE.perist("myStorageKey");
528528
```
529529

530-
### 💻 Web
531-
In a web environment, it is common to use the [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp) to store values permanently.
532-
AgileTs has set up the Local Storage by default.
533-
```ts {2}
534-
const App = new Agile({
535-
localStorage: true
536-
});
537-
```
538-
Therefore, we can use the `persist()` method out of the box.
539-
540-
### 📱 Mobile
541-
Since the Local Storage doesn't exist in a mobile environment,
542-
we have to resort to an alternative, such as the [Async Storage](https://reactnative.dev/docs/asyncstorage).
543-
AgileTs hasn't set up the Async Storage by default.
544-
Therefore, we need to create a [Storage](../storage/Introduction.md) Interface representing the Async Storage
545-
and register it to AgileTs.
546-
```ts {3-9}
547-
App.registerStorage(
548-
App.createStorage({
549-
key: "AsyncStorage",
550-
async: true,
551-
methods: {
552-
get: AsyncStorage.getItem,
553-
set: AsyncStorage.setItem,
554-
remove: AsyncStorage.removeItem,
555-
},
556-
}), {default: true} // Tells AgileTs that it is the default Storage
557-
);
558-
```
559-
560-
### 🔑 Local Storage Key
561-
Thus AgileTs can access and identify the stored value in the appropriate Storage,
562-
we have to define a unique `storageKey`.
563-
There are several ways to provide such required `storageKey` to the `persist()` method.
564-
565-
- **1.** Assign a unique key to the State itself.
566-
Because if no key is given to the `persist()` method,
567-
it takes the State key as `storageKey`.
568-
```ts {2}
569-
MY_STATE.key = "myCoolKey";
570-
MY_STATE.persist(); // Success (storageKey = 'myCoolKey')
571-
```
572-
- **2.** Pass the `storageKey` directly into the `persist()` method.
573-
```ts {1}
574-
MY_STATE.persist("myCoolPassedKey"); // Success (storageKey = 'myCoolPassedKey')
575-
```
576-
577-
If AgileTs couldn't find any fitting `storageKey`,
578-
it throws an error and doesn't persist the State `value`.
579-
```ts {2}
580-
MY_STATE.key = undefined;
581-
MY_STATE.persist(); // Error
582-
```
530+
### 🤓 Learn more
583531

584-
### 💾 `default` Storage
585-
In AgileTs we can register `multipe` Storages. However only one of these Storages can be the `default` Storage.
586-
The `default` Storage is used by the `persist()` method whenever no specific Storage is defined.
587-
```ts {1}
588-
MY_STATE.persist(); // persist in default Storage
589-
MY_STATE.persist({
590-
storageKeys: ["storageA"]
591-
}); // persist in Storage called 'storageA'
592-
```
593-
594-
### 📝 Multiple Storages
595-
Sometimes we may store States in different Storages.
596-
For example, _State A_ should be stored in _Storage B_, and _State B_ should be stored in _Storage A_.
597-
Then, we can define with `storageKeys` in which specific Storage the State `value` should be persisted.
598-
```ts {2}
599-
MY_STATE.persist({
600-
storageKeys: ["myCustomStorage"]
601-
});
602-
```
603-
By default, the State will be stored in the [default Storage](#-default-storage).
604-
```ts
605-
App.storages.config.defaultStorageKey; // Returns key of current default Storage
606-
```
532+
If you want to find out more about persisting Instances like States,
533+
checkout the [Persisting Data](../storage/PersistingData.md) Section.
607534

608535
### 📭 Props
609536

0 commit comments

Comments
 (0)