It's common for applications to store data on the client browser. AgileTs makes it pretty easy to achieve such goal.
Since many Agile Sub Instance can be persisted,
MY_INSTANCE as word placeholder for them.
In a web environment, it is common to use the Local Storage to store values permanently. AgileTs has set up the Local Storage by default.
Therefore, we can use the
persist() method out of the box.
Since the Local Storage doesn't exist in a mobile environment, we have to resort to an alternative, such as the Async Storage. AgileTs hasn't set up the Async Storage by default. Therefore, we need to create a Storage Interface representing the Async Storage and register it to AgileTs.
Thus AgileTs can access and identify the stored value in the appropriate Storage,
we have to define a unique
There are several ways to provide such required
storageKey to the
- 1. Assign a unique key to the AgilePersistInstance itself.
Because if no key is given to the
persist()method, it takes the AgilePersistInstance key as
storageKey.MY_INSTANCE.key = "myCoolKey";MY_INSTANCE.persist(); // Success (storageKey = 'myCoolKey')
- 2. Pass the
storageKeydirectly into the
persist()method.MY_INSTANCE.persist("myCoolPassedKey"); // Success (storageKey = 'myCoolPassedKey')
If AgileTs couldn't find any fitting
it throws an error and doesn't persist the AgilePersistInstance
In AgileTs we can register
multipe Storages. However only one of these Storages can be the
default Storage is used by the
persist() method whenever no specific Storage is defined.
Sometimes we may store AgilePersistInstances in different Storages.
For example, AgilePersistInstance A should be stored in Storage B, and AgilePersistInstance B should be stored in Storage A.
Then, we can define with
storageKeys in which specific Storage the AgilePersistInstance
value should be persisted.
By default, the AgilePersistInstance will be stored in the default Storage.