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

BREAKING CHANGE: storage migration #11

Merged
merged 8 commits into from
Sep 17, 2018
Merged

BREAKING CHANGE: storage migration #11

merged 8 commits into from
Sep 17, 2018

Conversation

nachomazzara
Copy link
Contributor

close #10

Add migrations for localstorage keys

@nachomazzara nachomazzara changed the title Feat/storage migration BREAKING CHANGE: storage migration Sep 14, 2018
const newData = migrations[version](data)
localStorage.setItem(
key,
JSON.stringify({ ...(newData as Object), storage: { version } })
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like this line is getting rid of the loading: true property that comes with the initial state of the storage reducer (see this line https://github.com/decentraland/decentraland-dapps/pull/11/files#diff-8544c74e5fd9e4b18f35209ce5efd2beR12) I dunno if that breaks anything, probably @nicosantangelo knows better than myself about this, but it seems like this should rather be:

JSON.stringify({ ...(newData as Object), storage: { ...newData.storage, version } })

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not a big deal because the loading will typically be set after creating the middleware, as a part of the redux-storage lib.
That said I think it doesn't hurt adding the spread, just in case

Also, can we get rid of the as Object? Maybe be a bit more specific?

Copy link
Contributor Author

@nachomazzara nachomazzara Sep 16, 2018

Choose a reason for hiding this comment

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

@nicosantangelo any is ok? If we want something more specific we need to pass the type when calling the method. For the built-in localstorage data will be defined internally inside decentraland-dapps but for new types, will need to be defined outside

@cazala I guess we are not picking the loading property from the store (I could check it again). We only use version https://github.com/decentraland/decentraland-dapps/pull/11/files#diff-dc8e3a1c851df38886297332fa450dc2R40

@cazala
Copy link
Contributor

cazala commented Sep 16, 2018

I left a question in the comments but it looks pretty good to me 👍

Copy link
Contributor

@cazala cazala left a comment

Choose a reason for hiding this comment

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

Oh btw can we update the README with this new feat plz 🙏 ❤️

README.md Outdated
storageKey: 'storage-key' // this is the key used to save the state in localStorage (required)
paths: [] // array of paths from state to be persisted (optional)
actions: [] // array of actions types that will trigger a SAVE (optional)
migrations: migrations // migration object that will migrate your localstorage
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be marked as (optional) too

README.md Outdated
The storage module allows you to save parts of the redux store in localStorage to make them persistent.
This module is required to use other modules like `Transaction` and `Translation`.
The storage module allows you to save parts of the redux store in localStorage to make them persistent and migrate it from different versions without loosing it.
This module is required to use other modules like `Transaction`, `Translation`, `Wallet` and `Storage`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The Storage module is irrelevant in this enumeration (this is already the Storage module)

README.md Outdated

```ts
export const migrations = {
1: migrateToVersion1(data),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the 1 migration ever exist? doesn't it start from 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, good catch!

README.md Outdated
@@ -347,7 +373,7 @@ export const rootReducer = storageReducerWrapper(

### Advanced Usage

This module is necessary to use other modules like `Transaction` or `Translation`, but you can also use it to make other parts of your dApp's state persistent
This module is necessary to use other modules like `Transaction`, `Translation`, `Wallet` and `Storage`, but you can also use it to make other parts of your dApp's state persistent
Copy link
Contributor

@cazala cazala Sep 17, 2018

Choose a reason for hiding this comment

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

Same as the comment above #11 (comment)

BREAKING CHANGE: storage migrations
BREAKING CHANGE: storage migrations
@cazala cazala merged commit 3d53434 into master Sep 17, 2018
@cazala cazala deleted the feat/storage-migration branch September 17, 2018 18:05
@cazala
Copy link
Contributor

cazala commented Sep 17, 2018

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

nicosantangelo pushed a commit to decentraland/marketplace-legacy that referenced this pull request Sep 18, 2018
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.

Versioning for localStorage keys
3 participants