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

Fix user settings in localStorage #220

Merged
merged 7 commits into from
Apr 22, 2021
Merged

Conversation

raucao
Copy link
Member

@raucao raucao commented Apr 18, 2021

Switch from ember-local-storage to localForage (and thus also IndexedDB 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

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
Copy link
Contributor

@fsmanuel fsmanuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @raucao just a couple of questions. Nothing blocking except the test comments.

Impressive how much dependencies this one addon removes: +117 −32,944 😲 /cc @bumi

app/services/local-data.js Outdated Show resolved Hide resolved
tests/unit/services/local-data-test.js Show resolved Hide resolved
app/routes/index.js Outdated Show resolved Hide resolved
@fsmanuel
Copy link
Contributor

Totally confused. You didn't even remove "ember-local-storage": "^1.7.2", from the package.json and just added a new addon and still have that crazy diff in package-lock.json.
When we build the kredits wrapper I was discussing with @bumi if one should get more kredits if the PR removes more than it adds. As an insentive to produce better software... =) That would be a big one for you @raucao ...

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); }
Copy link
Contributor

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.

Copy link
Member Author

@raucao raucao Apr 22, 2021

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.

@raucao
Copy link
Member Author

raucao commented Apr 22, 2021

CodeClimate is throwing a fit, but I disagree with it about the complexity of that function.

Copy link
Contributor

@fsmanuel fsmanuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean!

tests/unit/services/local-data-test.js Show resolved Hide resolved
super.beforeModel(...arguments);
await this.localData.setDefaultValues();
Copy link
Contributor

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)) {
Copy link
Contributor

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...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make CodeClimate happy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't help. :/

@raucao raucao force-pushed the bugfix/localstorage_user_settings branch from b3df207 to e5943dd Compare April 22, 2021 15:46
@raucao raucao merged commit 38e275d into master Apr 22, 2021
@raucao raucao deleted the bugfix/localstorage_user_settings branch April 22, 2021 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User settings in localStorage not saved anymore
3 participants