How to split stores into several files? #709
Answered
by
posva
hugoattal
asked this question in
Help and Questions
-
My store is getting pretty big, and I'd like to separate it into different files. Thing is, I don't want to lose the type inferring (it's soooo useful) I totally can do something like this: // store.ts
import { doThing } from "myActions"
export const useMyStore = defineStore({
id: "my-store",
actions: {
doThing(data: any) {
doThing(this, any);
}
}
state: () => ({
myStuff: any
})
});
export type TMyStore = ReturnType<typeof useMyStore >
// myActions.ts
import { TMyStore } from "store";
export function doThing(store: TMyStore, data: any): void {
store.myStuff = data;
} But I would prefer my store to look like this // store.ts
import { doThing } from "myActions"
export const useMyStore = defineStore({
id: "my-store",
actions: {
doThing
}
state: () => ({
myStuff: any
})
});
// myActions.ts
// ??? Is this something possible? |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Oct 8, 2021
Replies: 1 comment 1 reply
-
I would avoid splitting the store into multiple files. If anything split the store into multiple stores or extract heavy functions outside of actions and rely on passing the necessary information of the store as arguments (instead of passing the whole store) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
hugoattal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would avoid splitting the store into multiple files. If anything split the store into multiple stores or extract heavy functions outside of actions and rely on passing the necessary information of the store as arguments (instead of passing the whole store)