davestewart/vue-class-store

create a factory function so classes can be used not only in components

Closed this issue · 5 comments

create a factory function so classes can be used not only in components

Hi Patrick.

I don't think I understand your request.

You can use Vue Class Store anywhere.

What seems to be the problem?

Can you provide a code example?

Sure for a global store you currently use:

export default { provide () { return { $products: new ProductsStore() } }, }

now this single instance of $products is now available in all the components but not in other classes or js functions. To make this work the composition API comes to mind.

const useProductStore = createNewStore(new ProductsStore())

now createNewStore returns a function that always returns the same instance of ProductStore() so you can use it anywhere with:
const store = useProductStore()

Ah, I see.

Do you not think this would be best handled by the individual developer?

It should be as easy as exporting a store from @/store/index.ts.

export const useProductStore = createNewStore(new ProductsStore())

OK. Thanks for the clarification.

Closing this as I think users should handle store instantiation themselves.