hoodiehq / hoodie-client

:dog: Client API for the Hoodie server
Apache License 2.0
34 stars 25 forks source link

drop localStorage usage #110

Closed gr2m closed 7 years ago

gr2m commented 7 years ago

πŸ“‹ part of https://github.com/hoodiehq/camp/issues/101. closes #116, closes #117, closes #118


This hurts me a bit, because the API becomes more complex as it is today. Instead of just doing

if (hoodie.account.isSignedIn()) {
  alert('Welcome, ' + hoodie.account.username)
}

we now have to do

hoodie.ready.then(function () {
  if (hoodie.account.isSignedIn()) {
    alert('Welcome, ' + hoodie.account.username)
  }
})

We could only support the synchronous API without a bootstrapping because we relied on the synchronous APIs of localStorage. We decided that we have to drop that dependency if we want hoodie to run in other environments where localStorage is not available, like Service Worker, Node.js or native environments like React Native or Electron.

On the plus side, once hoodie.ready is resolved, the API remains as it is today, and we can expose a hook which would allow plugins for asynchronous initialisation, too.

Progress

BREAKING CHANGE:

Hoodie dropped its dependency on localStorage in order to work in non-browser environments. In order to make that work we have to use async store APIs to load the current state like the session id, username or the connection status.

The APIs hoodie.account, hoodie.store and hoodie.connectionStatus can now only be used after the promise returned by hoodie.ready resolves.

gr2m commented 7 years ago

πŸ”” @hoodiehq/maintainers this PR is ready for review πŸ‘€

It’s the final one to drop the localStorage dependency from Hoodie and make it work everywhere PouchDB does :) πŸ”œ https://github.com/hoodiehq/camp/issues/101

Please let me do the merging.