@@ -207,11 +207,13 @@ Returns the [State](../state/Introduction.md) it was called on.
207207
208208::: info
209209
210- Only useful if we use the [ ` type ` ] ( #type ) function.
210+ Only useful if we have used the [ ` type ` ] ( #type ) function to define the type of our State .
211211
212212:::
213213
214- Checks if passed value has correct value type, defined with the [ ` type ` ] ( #type ) function.
214+ Checks if the given value has the correct type at runtime.
215+ It compares whether the value has the same type, which was previously
216+ defined with help of the [ ` type ` ] ( #type ) function.
215217``` ts {2,3}
216218MY_STATE .type (String );
217219MY_STATE .hasCorrectType (" hi" ); // Returns 'true'
@@ -233,8 +235,8 @@ MY_STATE.hasCorrectType(12); // Returns 'false'
233235
234236## ` undo `
235237
236- Reverses our latest State Value mutation.
237- Be aware that it can only reverses one State change,
238+ Reverses the latest State Value mutation.
239+ Be aware that it can only reverses one State change at once ,
238240that's why we can't do ` undo().undo().undo() ` to get to the State Value from before 3 State changes.
239241``` ts {3}
240242MY_STATE .set (" hi" ); // State Value is 'hi'
@@ -263,9 +265,7 @@ Returns the [State](../state/Introduction.md) it was called on.
263265
264266## ` reset `
265267
266- Resets our State Value to its initial Value.
267- If you are wondering what the initial Value is,
268- it is the Value which was firstly assigned to our State.
268+ Sets the State Value to its initial Value.
269269``` ts {4}
270270const MY_STATE = App .createState (" hi" ); // State Value is 'hi'
271271MY_STATE .set (" bye" ); // State Value is 'bye'
@@ -296,11 +296,11 @@ Returns the [State](../state/Introduction.md) it was called on.
296296
297297::: info
298298
299- Only relevant for State Values which have ` object ` as type.
299+ Only relevant for States which have an ` object ` as value type.
300300
301301:::
302302
303- Merges an object with changes into the current State Value.
303+ Merges an object into the current State Value object .
304304``` ts {2,5}
305305const MY_STATE = App .createState ({id: 1 , name: " frank" }); // State Value is '{id: 1, name: "frank"}'
306306MY_STATE .patch ({name: " jeff" }); // State Value is '{id: 1, name: "jeff"}'
@@ -311,13 +311,14 @@ MY_STATE.patch({hello: "there"}); // Error
311311
312312### ❓ Deepmerge
313313Unfortunately the ` patch ` function doesn't support deep merges yet.
314- Currently, the merge only happens at the top-level of our Objects, and it doesn't look for deep changes.
315- If it cannot find a particular property, it will add it to the top-level of the object.
314+ Currently, the merge only happens at the top-level of our objects.
315+ This means, that it doesn't look for deep changes,
316+ if it cannot find a particular property, it will add it at the top-level of the object.
316317``` ts {2}
317318const MY_STATE = App .createState ({things: { thingOne: true , thingTwo: true }}); // State Value is {things: { thingOne: true, thingTwo: true }}
318319MY_STATE .patch ({ thingOne: false }); // State Value is {things: { thingOne: true, thingTwo: true }, thingOne: false}
319320```
320- If we don't want to add not existing properties to our State Value object, we can set ` addNewProperties ` to _ false_ .
321+ If we don't want to add not existing properties to the object, we can set ` addNewProperties ` to _ false_ .
321322``` ts {2}
322323const MY_STATE = App .createState ({things: { thingOne: true , thingTwo: true }}); // State Value is {things: { thingOne: true, thingTwo: true }}
323324MY_STATE .patch ({ thingOne: true }, {addNewProperties: false }); // State Value is {things: { thingOne: true, thingTwo: true }}
@@ -346,7 +347,7 @@ Returns the [State](../state/Introduction.md) it was called on.
346347## ` watch `
347348
348349Observes our State and calls a callback function on each State Value mutation.
349- ``` ts
350+ ``` ts {1-4}
350351const response = MY_STATE .watch ((value , key ) => {
351352 console .log (value ); // Returns current State Value
352353 console .log (key ); // Key of Watcher ("Aj2pB")
@@ -355,19 +356,19 @@ const response = MY_STATE.watch((value, key) => {
355356console .log (response ); // "Aj2pB" Random generated Key to idetify the watcher callback
356357```
357358We recommend giving each ` watcher ` callback a unique key to properly identify it later.
358- ``` ts
359+ ``` ts {1-3}
359360const something = MY_STATE .watch (" myKey" , (value ) => {
360361 // do something
361362});
362363
363364console .log (response ); // State Instance it was called on
364365```
365366A proper identification is for instance necessary,
366- if we want to clean up our watcher callback to avoid memory leaks .
367+ to clean up our watcher callback later .
367368
368369### ❓ When should I cleanup
369- If we need to use our watcher in component code, it is important to [ clean up] ( #removewatcher ) , as if
370- the component unmounts, and the watcher remains it can cause memory leaks.
370+ If we have to use a watcher in component code, it is important to [ clean up] ( #removewatcher ) after using it.
371+ Because if the component unmounts, and the watcher remains it can cause memory leaks.
371372``` ts
372373MY_STATE .removeWatcher (cleanupKey );
373374```
@@ -410,9 +411,8 @@ Otherwise, it generates us a random Key and returns this.
410411## ` removeWatcher `
411412
412413Removes ` watcher ` callback at specific Key.
413- Such a cleanup is important, after we have no reason to use the callback
414- anymore. For instance after a Component has been unmounted, we should cleanup
415- the callback to avoid memory leaks.
414+ Such a cleanup is important, after we have no reason to use the watcher callback anymore.
415+ For instance after a Component has been unmounted to avoid memory leaks.
416416``` ts
417417MY_STATE .removeWatcher (" myKey" );
418418```
@@ -496,9 +496,8 @@ Returns the [State](../state/Introduction.md) it was called on.
496496
497497## ` persist `
498498
499- Preserves State Value in the appropriate local storage
500- for the current environment. No matter if Mobile or Web
501- environment as long as we have configured our [ Storage] ( ../storage/Introduction.md ) correctly.
499+ Preserves State Value in the appropriate local storage for the current environment.
500+ No matter if Mobile or Web environment as long as we have configured our [ Storage] ( ../storage/Introduction.md ) correctly.
502501``` ts
503502MY_STATE .perist (" myPersistKey" );
504503```
@@ -511,6 +510,7 @@ const App = new Agile({
511510 localStorage: true
512511})
513512```
513+ So there is noting to setup here.
514514
515515### 📱 Mobile
516516In the mobile environment the Local Storage unfortunately doesn't exist,
@@ -526,13 +526,13 @@ App.registerStorage(
526526 set: AsyncStorage .setItem ,
527527 remove: AsyncStorage .removeItem ,
528528 },
529- })
529+ }), {default: true }
530530);
531531```
532532
533533### 🔑 Local Storage Key
534- If we want to persist our State,
535- we have two options to provide the ` persist ` function a required Storage Key.
534+ To persist our State,
535+ we have two options to provide the ` persist ` function the ** required** Storage Key.
536536
537537- ** 1.** Assign a unique Key to our State,
538538 because if no key was given to the ` persist ` function,
@@ -546,21 +546,21 @@ we have two options to provide the `persist` function a required Storage Key.
546546 MY_STATE .persist (" myCoolKey" ); // Success
547547 ```
548548
549- If AgileTs couldn't find any Key , it drops an error and doesn't persist the State Value.
549+ If AgileTs couldn't find any key , it drops an error and doesn't persist the State Value.
550550``` ts {2}
551551MY_STATE .key = undefined ;
552552MY_STATE .persist (); // Error
553553```
554554
555555### 📝 Multiple Storages
556- If our Application for whatever reason has two registered Storages that get actively used.
557- And we don't want to store our State Value in the default Storage, which gets automatically used by the ` perist ` function.
558- We can define the Storages it should use instead in the ` config ` object.
559- ``` ts
556+ If our Application for whatever reason has more than one registered Storages that get actively used.
557+ We can define with help of the ` storageKeys ` in which Storage the ` persist ` function stores the State Value.
558+ ``` ts {2}
560559MY_STATE .persist ({
561560storageKeys: [" myCustomStorage" ]
562561})
563562```
563+ By default, it gets stored in the default Storage.
564564
565565### 📭 Props
566566
@@ -590,8 +590,8 @@ MY_STATE.onLoad((success) => {
590590console .log (` Value '${MY_STATE .value }' got loaded into the State! Success? ${success } ` )
591591});
592592```
593- For instance this might be useful, if we want to show a loading indicator until
594- we are able to show the persisted Value.
593+ For instance this might be useful, to show a loading indicator until
594+ the persisted Value got loaded .
595595
596596### 📭 Props
597597
@@ -656,12 +656,12 @@ MY_STATE.exists; // Returns 'true'
656656
657657## ` is `
658658
659- Checks if the State Value _ is equal_ to a specific value.
659+ Checks if the State Value _ is equal_ to the provided value.
660660Equivalent to ` === ` .
661661``` ts {2,3}
662662const MY_STATE = App .createState (" hi" );
663- MY_STATE .is (" bye" ); // Returns false
664- MY_STATE .is (" hi" ); // Returns true
663+ MY_STATE .is (" bye" ); // Returns ' false'
664+ MY_STATE .is (" hi" ); // Returns ' true'
665665```
666666
667667### 📭 Props
@@ -685,12 +685,12 @@ MY_STATE.is("hi"); // Returns true
685685
686686## ` isNot `
687687
688- Checks if the State Value _ isn't equal_ to a specific value.
688+ Checks if the State Value _ isn't equal_ to the provided value.
689689Equivalent to ` !== ` .
690690``` ts {2,3}
691691const MY_STATE = App .createState (" hi" );
692- MY_STATE .isNot (" bye" ); // Returns true
693- MY_STATE .isNot (" hi" ); // Returns false
692+ MY_STATE .isNot (" bye" ); // Returns ' true'
693+ MY_STATE .isNot (" hi" ); // Returns ' false'
694694```
695695
696696### 📭 Props
@@ -716,7 +716,7 @@ MY_STATE.isNot("hi"); // Returns false
716716
717717::: info
718718
719- Only relevant for State Values which have ` boolean ` as type.
719+ Only relevant for States which have an ` boolean ` as value type.
720720
721721:::
722722
0 commit comments