-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix user settings in localStorage #220
Conversation
Switch from ember-local-storage to localForage (and thus IndexedDB by default). Contains a generic function which allows to extend a defaultValues object with more default data to be set for empty local storages. fixes #219
Leftover from hacking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally confused. You didn't even remove |
app/services/local-data.js
Outdated
Object.keys(defaultValues[storeName]).forEach(async key => { | ||
const value = await store.getItem(key); | ||
const defaultValue = defaultValues[storeName][key]; | ||
if (isEmpty(value)) { await store.setItem(key, defaultValue); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be aware that forEach
doesn't wait for any of the asynchronous functions before iterating over the next element. So the await
for the store.setItem()
call is superfluous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have refactored the function to use for ... of
. Thanks.
Values are set by the localData service when loading the app now.
CodeClimate is throwing a fit, but I disagree with it about the complexity of that function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and clean!
super.beforeModel(...arguments); | ||
await this.localData.setDefaultValues(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
} | ||
|
||
async setDefaultValues () { | ||
for (const storeName of Object.keys(defaultValues)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you can try is assign const defaultValuesKeys = Object.keys(defaultValues);
outside the class...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make CodeClimate happy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't help. :/
b3df207
to
e5943dd
Compare
Switch from
ember-local-storage
tolocalForage
(and thus alsoIndexedDB
by default).Contains a generic function which allows to extend a
defaultValues
object in the service with more default data to be set for empty local storages.Testing this manually is possible by just seeing if loading the app from the root URL redirects to the last channel you had open or not (should not do on master, but should do with this fix).
fixes #219