Ionic Storage and SQLite

Some heuristics to make your life with Ionic Storage considerably less painful:

The Prime Directive: the only thing it should be used for is a “message-in-a-bottle” scenario where you have something now that you want to tell the next time the app is launched.

From which follows two important corollaries:

  • Only read from Storage once, at app launch (or whenever the relevant data is first needed)
  • You are free to write optimistically. If you want to worry about errors, fine, but you don’t need to chain and return set Promises.

Incidentally, if you are going to care about set returns, Promise.all is more idiomatic than cascading then chains.

So if we’re only allowed to read from Storage once, then how do I communicate new user information from one page to another in one running instance of my app? Via a service provider that exposes an Observable of user information. All places in the app that care about it can subscribe to it and always receive the latest data.

1 Like