Skip to content

Local Storage

To save data to or load data from local storage, the user must be already authenticated.

  • Check that TheM.user.isAuthenticated is true.
  • If TheM.user or TheM.common is undefined, then the necessary submodules have not yet been initialized. Do TheM.doInit("common user") to initialize the common and user modules.
  • If TheM.user.isAuthenticated = false, then the user is not logged in. Do TheM.user.doLogin({//user credentials}).

Many of the main-level objects have their own .doLoad() and .doSave() methods.TheM.SUBMODULE_NAME_HERE.doSave(); saves data of TheM.user, TheM.accounts, TheM.fxrates, etc. in a compressed form in the persistent localStorage. Likewise, TheM.SUBMODULE_NAME_HERE.doLoad(); restores locally stored data.

Save data right after updates and load data right after authentication (prior to updates) in order for your web-app to be as quick and responsive as possible. Once TheM.user.isAuthenticated is true, then you can load current user data from the server using TheM.user.doUpdate(true).

Mind browser limits on localStorage. Modern browsers allow ample data storage limits (and this framework uses zip compression). However, there is still a limit.

On Android and in the web, the framework uses a webworker which compresses and stores the data in the indexedDB. On iOS indexedDB is not available, thus localStorage is used.