Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/HalJsonVuexPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ export function HalJsonVuexPlugin<RootEndpoint extends ResourceInterface, FullSt
function setLoadPromiseOnStore<StoreType> (uri: string, loadStoreData: Promise<StoreData<StoreType>> | null = null) {
const promise: SerializablePromise<StoreData<StoreType>> = loadStoreData || Promise.resolve(store.state[opts.apiName][uri])
promise.toJSON = () => '{}' // avoid warning in Nuxt when serializing the complete Vuex store ("Cannot stringify arbitrary non-POJOs Promise")
store.state[opts.apiName][uri]._meta.load = promise
store.commit('setLoadPromise', {
Copy link
Member

Choose a reason for hiding this comment

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

Have you read the comment on line 399? I think I had to do it this way, otherwise I would run into problems... Change LGTM, but I'm unsure because of that comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, somehow the comment is here again, deleted it in some somewhere along they way, now its here again..
Nice that the comment is there, but i don't know what the problems were then, i did not find any hints in the commit which added the comment, no tests broke...

I tried it against a ecamp3 with vue3 with a strict store, but i had not enough substance to test it. (We don't have any interactivity except the login which works yet...)
But with this change you can login, you can at least fetch some data without setting the store to strict:false.

And as you can see if you check out the change: if you set the store to strict, this change is needed.

If you can remember what the problem was then i am eager to hear it... else we will find this problem again if its still there.

uri,
promise
})
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/storeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { del, set } from 'vue-demi'

import type { MutationTree } from 'vuex/types'

import type StoreData from './interfaces/StoreData'
import type { StoreData, SerializablePromise } from './interfaces/StoreData'

export const state = {}
export type State<StoreType> = Record<string, StoreData<StoreType>>
Expand Down Expand Up @@ -30,6 +30,14 @@ export const mutations: MutationTree<State<unknown>> = {
set(state[uri]._meta, 'reloading', false)
})
},
/**
* Adds entities loaded from the API to the Vuex store.
* @param state Vuex state
* @param data An object mapping URIs to entities that should be merged into the Vuex state.
*/
setLoadPromise<StoreType> (state: State<StoreType>, data: { uri: string, promise: SerializablePromise<StoreData> }): void {
state[data.uri]._meta.load = data.promise
},
/**
* Marks a single entity in the Vuex store as reloading, meaning a reloading network request is currently ongoin.
* @param state Vuex state
Expand Down
11 changes: 9 additions & 2 deletions tests/apiOperations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ let axiosMock
let store
let vm

describe('Using dollar methods', () => {
describe.each(
[
false,
true
]
)('Using dollar methods and store.strict: %s', (strict) => {
beforeAll(() => {
axios.defaults.baseURL = 'http://localhost'
})

beforeEach(() => {
axiosMock = new MockAdapter(axios)

store = createStore({})
store = createStore({
strict
})

const installApi = {
install (app) {
Expand Down
Loading