You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 15, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/packages/core/features/collection/Methods.md
+60-20Lines changed: 60 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -988,25 +988,27 @@ All Item `values` of the Collection.
988
988
989
989
## `persist()`
990
990
991
-
With `persist()` we preserve the State Value in the appropriate local storage for the current environment.
992
-
No matter if Mobile or Web environment as long as we have configured our [Storage](../storage/Introduction.md) correctly.
991
+
Preserves Collection Value in the appropriate local storage for the current environment.
992
+
No matter if Mobile or Web environment as long as the [Storage](../storage/Introduction.md) Interface is configured correctly.
993
993
```ts
994
994
MY_COLLECTION.perist("myPersistKey");
995
995
```
996
996
997
997
### 💻 Web
998
-
Most people persisting something in a web environment, use the [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp).
998
+
In a web environment it is common to use the [Local Storage](https://www.w3schools.com/html/html5_webstorage.asp) to permanently store a specific value
999
999
Luckily AgileTs has already set up the Local Storage by default.
1000
1000
```ts {2}
1001
1001
const App =newAgile({
1002
1002
localStorage: true
1003
1003
})
1004
1004
```
1005
+
So we can use the `persist()` method out of the box.
1005
1006
1006
1007
### 📱 Mobile
1007
1008
In a mobile environment the Local Storage doesn't exist,
1008
-
so we have to use an alternative like the [Async Storage](https://reactnative.dev/docs/asyncstorage).
1009
-
The Async Storage isn't registered to AgileTs by default, so we have to do it on our own.
1009
+
so we need an alternative like the [Async Storage](https://reactnative.dev/docs/asyncstorage).
1010
+
The Async Storage isn't setup by default, so we need create a [Storage](../storage/Introduction.md) Interface
1011
+
and register it to AgileTs on our own.
1010
1012
```ts {3-9}
1011
1013
App.registerStorage(
1012
1014
App.createStorage({
@@ -1022,11 +1024,12 @@ App.registerStorage(
1022
1024
```
1023
1025
1024
1026
### 🔑 Local Storage Key
1025
-
For persisting a Collection we have two options to provide the required `storage key`.
1027
+
To persist a Collection we need a `storage key`, which is used to identify the stored value later.
1028
+
There are two ways to provide such required `storage key` to the `persist()` method.
1026
1029
1027
-
-**1.** Assign a unique key to the Collection,
1028
-
because if no key has been passed into the `persist()` function,
1029
-
it uses the Collection key as `storage key`.
1030
+
-**1.** Assign a unique key to the Collection itself.
1031
+
Because if no key is given to the `persist()` function,
1032
+
it takes the Collection key as `storage key`.
1030
1033
```ts {2}
1031
1034
MY_COLLECTION.key="myCoolKey";
1032
1035
MY_COLLECTION.persist(); // Success
@@ -1036,19 +1039,20 @@ For persisting a Collection we have two options to provide the required `storage
1036
1039
MY_COLLECTION.persist("myCoolKey"); // Success
1037
1040
```
1038
1041
1039
-
If AgileTs couldn't find any key to use as`storage key`,
1040
-
it drops an error and doesn't persist the Collection value.
1042
+
If AgileTs couldn't find any key that could be used as a`storage key`,
1043
+
it throws an error and doesn't persist the Collection value.
1041
1044
```ts {2}
1042
1045
MY_COLLECTION.key=undefined;
1043
1046
MY_COLLECTION.persist(); // Error
1044
1047
```
1045
1048
1046
1049
### 📝 Multiple Storages
1047
-
In case our application uses more than one registered Storage,
1048
-
we can define with the help of `storageKeys` in which Storage the Collection data should be stored.
1050
+
Sometimes it may happen that we store Collections in different Storages.
1051
+
For example, Collection A should be stored in Storage B and Collection B should be stored in Storage A.
1052
+
Therefore, we can use `storageKeys` to define in which specific Storage the Collection value should be persisted.
1049
1053
```ts {2}
1050
1054
MY_COLLECTION.persist({
1051
-
storageKeys: ["myCustomStorage"]
1055
+
storageKeys: ["myCustomStorage"]
1052
1056
})
1053
1057
```
1054
1058
By `default`, it will be stored in the `default` Storage.
@@ -1294,6 +1298,7 @@ Array<number | string>
1294
1298
```
1295
1299
1296
1300
1301
+
1297
1302
<br />
1298
1303
1299
1304
---
@@ -1307,8 +1312,8 @@ Array<number | string>
1307
1312
With `remove()` we are able to remove Item/s from
1308
1313
1309
1314
-### `everywhere()`
1310
-
Removes the Item/s at `itemKey/s` from the whole Collection and all [Groups](./group/Introduction.md) / [Selectors](./selector/Introduction.md),
1311
-
so from everywhere.
1315
+
Removes the Item/s at `itemKey/s` from the entire Collection and all [Groups](./group/Introduction.md) / [Selectors](./selector/Introduction.md),
1316
+
i.e. from everywhere.
1312
1317
```ts
1313
1318
MY_COLLECTION.remove('item1').everywhere();
1314
1319
```
@@ -1321,8 +1326,8 @@ With `remove()` we are able to remove Item/s from
1321
1326
1322
1327
:::info
1323
1328
1324
-
Be aware that a standalone `remove()` doesn't do anything,
1325
-
so we always have to add `.everywhere()` or `.fromGroups()`.
1329
+
Note that a standalone `remove()` doesn't do anything,
1330
+
so we have to always add `.everywhere()` or `.fromGroups()`.
1326
1331
1327
1332
:::
1328
1333
@@ -1336,8 +1341,43 @@ so we always have to add `.everywhere()` or `.fromGroups()`.
0 commit comments