Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop localStorage usage #126

Merged
merged 9 commits into from Dec 23, 2016
Merged

drop localStorage usage #126

merged 9 commits into from Dec 23, 2016

Conversation

gr2m
Copy link
Member

@gr2m gr2m commented Dec 10, 2016

part of hoodiehq/camp#101

@gr2m gr2m changed the title WIP: drop localStorage usage drop localStorage usage Dec 18, 2016
BREAKING CHANGE:

The `pre:*` and `post:*` events introduced in #65 have now been removed in favor of a proper `account.hook.{before,after}` API. See https://github.com/hoodiehq/hoodie-account-client#hooks for more details.

This is not technically a breaking change as the `pre:*` and `post:*` events have not been documented, but as they are used by `@hoodie/client` we decided to make this a breaking change nevertheless
BREAKING CHANGE:

As part of our effort to make Hoodie Client compatible with Service Worker and other environments that do not have access to localStorage, we have to make the Account Client compatible with async store APIs. That means we can’t load the current account state synchronously, so this is no longer be possible:

```js
var account = new Account({
  url: /api
})
if (account.isSignedIn()) {
  sayHi(account.username)
}
```

Starting with this release, you have to wrap the synchronous methods and properties into `account.ready.then()`

```js
account.ready.then(function () {
  if (account.isSignedIn()) {
    sayHi(account.username)
  }
})
```

By default, the account will still use localStorage (via [humble-localstorage](https://github.com/gr2m/humble-localstorage)) to persist its state, but it will now be made asynchronous. In order to use another storage a new `options.cache` argument can be passed to the Account constructor:

```js
var account = new Account({
  url: /api,
  cache: {
    set: writeAccountState
    get: getAccountState,
    unset: clearAccountState,
  }
})
```

All three `options.cache` methods must return promises. `options.cache.get` must resolve with the persisted account properties or an empty object.
@gr2m
Copy link
Member Author

gr2m commented Dec 23, 2016

I got this one

@gr2m gr2m self-assigned this Dec 23, 2016
@gr2m gr2m merged commit 962841a into master Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant