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

Migrate Vuex store to Pinia #1265

Merged
merged 5 commits into from
Sep 7, 2022
Merged

Migrate Vuex store to Pinia #1265

merged 5 commits into from
Sep 7, 2022

Conversation

mvandenburgh
Copy link
Member

Closes #1261

For reference, I mostly followed this guide.

One thing to note is that Pinia has a slightly different paradigm than Vuex when it comes to "stores" and "modules". Vuex had one central store that could be divided into several modules. On the other hand, Pinia has no concept of a first-class module, instead, you have multiple stores. So, in this PR I have converted our Vuex store with a dandiset module, to a single Pinia DandisetStore.

@mvandenburgh mvandenburgh marked this pull request as draft September 6, 2022 20:15
Copy link
Member

@jjnesbitt jjnesbitt left a comment

Choose a reason for hiding this comment

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

LGTM just a couple suggestions

web/src/stores/dandiset.ts Outdated Show resolved Hide resolved
web/src/rest.ts Show resolved Hide resolved
Co-authored-by: Jacob Nesbitt <jjnesbitt2@gmail.com>
@mvandenburgh mvandenburgh merged commit fd4a964 into master Sep 7, 2022
@mvandenburgh mvandenburgh deleted the upgrade-to-pinia branch September 7, 2022 17:06
@dandibot
Copy link
Member

dandibot commented Sep 8, 2022

🚀 PR was released in v0.2.46 🚀

@dandibot dandibot added the released This issue/pull request has been released. label Sep 8, 2022
Copy link
Member

@waxlamp waxlamp left a comment

Choose a reason for hiding this comment

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

This is very cool. Thanks @mvandenburgh!

async initializeDandisets({ identifier, version }: Record<string, string>) {
this.uninitializeDandisets();

// this can be done concurrently, don't await
Copy link
Member

Choose a reason for hiding this comment

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

Is this a TODO?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I believe it's just there to clarify why there's no await in front of the following method so someone doesn't see it and think it's a bug. It was there in the old vuex code, I just copied it over.

Copy link
Member

Choose a reason for hiding this comment

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

The confusion I had was between what you just said (explaining why the first statement has no await) and suggesting that someone should remove the following two awaits and make all three operations concurrent.

schema: null,
}),
getters: {
version: (state) => (state.dandiset ? state.dandiset.version : draftVersion),
Copy link
Member

Choose a reason for hiding this comment

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

Can we apply TS types to these functions? It would make the list of getters that much more legible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike Vuex with direct-vuex, Pinia is fully typed, so the types of every function parameter/return value here are inferred automatically without needing to manually specify them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, maybe I'm misunderstanding what you're saying. Are you just asking for explicit types to be added? Like

Suggested change
version: (state) => (state.dandiset ? state.dandiset.version : draftVersion),
version: (state): string => (state.dandiset ? state.dandiset.version : draftVersion),

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I meant the latter. It's not necessary to fill them all in now, but I think one of the major benefits of TypeScript is that the types are checked by the machine, but also legible to the human.

web/src/stores/dandiset.ts Show resolved Hide resolved
web/src/App.vue Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade Vuex to Pinia
4 participants