-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
options.cache
and account.ready
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.
- Loading branch information
Showing
25 changed files
with
294 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
module.exports = getId | ||
|
||
var generateId = require('../utils/generate-id') | ||
|
||
function getId (state) { | ||
if (!state.account) { | ||
state.account = { | ||
id: generateId() | ||
} | ||
state.store.set(state.account) | ||
throw new Error('account.id not yet accessible, wait for account.ready to resolve') | ||
} | ||
return state.account.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.