diff --git a/src/HalJsonVuexPlugin.ts b/src/HalJsonVuexPlugin.ts index d979395..09b9bfe 100644 --- a/src/HalJsonVuexPlugin.ts +++ b/src/HalJsonVuexPlugin.ts @@ -407,7 +407,10 @@ export function HalJsonVuexPlugin (uri: string, loadStoreData: Promise> | null = null) { const promise: SerializablePromise> = 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', { + uri, + promise + }) } /** diff --git a/src/storeModule.ts b/src/storeModule.ts index 380122c..491be5d 100644 --- a/src/storeModule.ts +++ b/src/storeModule.ts @@ -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 = Record> @@ -30,6 +30,14 @@ export const mutations: MutationTree> = { 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 (state: State, data: { uri: string, promise: SerializablePromise }): 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 diff --git a/tests/apiOperations.spec.js b/tests/apiOperations.spec.js index c8f6b9e..7007a23 100644 --- a/tests/apiOperations.spec.js +++ b/tests/apiOperations.spec.js @@ -22,7 +22,12 @@ 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' }) @@ -30,7 +35,9 @@ describe('Using dollar methods', () => { beforeEach(() => { axiosMock = new MockAdapter(axios) - store = createStore({}) + store = createStore({ + strict + }) const installApi = { install (app) {