-
Thanks for answering my questions, this migration is a huge job so it really helps to clarify a few things. In vuex-orm we had vuex stores linked with the vuex-orm models. This happened when the models were registered, which no longer happens in pinia-orm.
Then we could use vuex actions directly from the model import, and use the model import for vuex-orm queries.
Can pinia-orm models and pinia stores be linked so I can access the state/and actions from the model import? I see there is the piniaStore() method on the model, but even if I give them the same name, they don't seem to be linked. I'm guessing the model goes into it's own name space, and is a seperate store. I can just import them seperately, it just means that sometimes we have 15 models imports in one file. Now we have another 15 lines of useRepo definitions, and another 15 lines of useStore imports.
Just wanted to clarify that I'm understanding this right. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey again 😄 As you mentioned correctly there is no registration anymore like in The If it's just about line saving and you use the Repo only once in the code then you can also write: import { useRepo } from 'pinia-orm'
import Media from '@/models/media';
import { useMediaStore } from '@/state/media';
useMediaStore().fetchMedia().then(
response => {
if (!response.data.errors) {
useRepo(Media).save(response.data.media)
}
}
) One line less 😄 . You could use a helper function if your models are all initlized the same way like: import { useRepo } from 'pinia-orm'
export function initRepo(model, stateStore, method) {
stateStore[method]().then(
response => {
if (!response.data.errors) {
useRepo(model).save(response.data.media)
}
}
)
} or you create a custom repository where you put this logic in. Which would be semanticly the right choice 😉 |
Beta Was this translation helpful? Give feedback.
Hey again 😄
As you mentioned correctly there is no registration anymore like in
vuex-orm-next
. I was thinking about your case if it makes sense giveuseRepo
an option to pass something likestate
, but in my opnionen there is no benefit.The
piniaStore
method is not on theModel
. It*s on theRepository
.Model
will never have likevuex-orm-net
business logic becausepinia-orm
andvuex-orm-next
are follwing the Data Mapper PatternIf it's just about line saving and you use the Repo only once in the code then you can also write: