Giter VIP home page Giter VIP logo

Comments (6)

posva avatar posva commented on May 12, 2024 3

yes, it breaks current instance because it creates one itself to outlive component scoped for the state, but creating it outside of a component, by calling useStore for the first time, doesn't break any current instance 🙂

from pinia.

posva avatar posva commented on May 12, 2024

Yeah, this is a limitation that needs to wait for vuejs/rfcs#212. For now, it's necessary to call the useStore function at the end of setup or call pinia.store(useStore) for each store in your main.js file (it will also remvoe the code splitting)

from pinia.

LadislavBohm avatar LadislavBohm commented on May 12, 2024

I am wondering whether there is an easier way to call pinia.store for all stores. Currently this feels like the biggest issue for me as moving things around setup function does not make it readable or maintainable. Also not always possible and required multiple instances of pinia stores around one setup function.

In some compiled language I would use reflection to register stuff like that within an assembly. Doesn't seem like the mentioned RFC got a lot of positive feedback 😰

from pinia.

posva avatar posva commented on May 12, 2024

It's annoying for me too. The easiest workaround is to import all stores in your main.js file and call pinia.store(useStore) to instantiate them.

The RFC will go through a way or another because there is a need for it

from pinia.

LadislavBohm avatar LadislavBohm commented on May 12, 2024

Thanks I will end up doing that. Generally is this the same reason why this is happening?

const firstInstance = getCurrentInstance(); //resolves properly
const userEditStore = useSomeStore();
const secondInstance = getCurrentInstance(); //always null

This seems to be the reason why useVuelidate which is internally calling getCurrentInstance is failing. I wanted to bind vuelidate directly to my store state so I will just import all stores at start like you mentioned.

from pinia.

lk0606 avatar lk0606 commented on May 12, 2024

@posva

I use pinia^2.0.13 in vue2, and postinstall npx vue-demi-switch 2, alll ok.
but when i use onBeforeMount or others Lifecycle in setup, how can i resolve it?
image

from pinia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.