// a different instance of b store was used
expect(bStore.state.b).toBe('c')
})
+
+ it('can force the req', () => {
+ const req1 = {}
+ const req2 = {}
+ const aStore = useA(req1)
+
+ let bStore = useB(req2)
+ bStore.state.b = 'c'
+
+ aStore.swap()
+ expect(aStore.state.a).toBe('b')
+ // a different instance of b store was used
+ expect(bStore.state.b).toBe('c')
+ bStore = useB(req1)
+ expect(bStore.state.b).toBe('a')
+ })
})
* be able to reset the store instance between requests on the server
*/
-const storesMap = new WeakMap<
+export const storesMap = new WeakMap<
NonNullObject,
Record<string, Store<any, any, any, any>>
>()
}) {
const { id, state, getters, actions } = options
- return function useStore(): Store<Id, S, G, A> {
+ return function useStore(reqKey?: object): Store<Id, S, G, A> {
+ if (reqKey) setActiveReq(reqKey)
const req = getActiveReq()
let stores = storesMap.get(req)
if (!stores) storesMap.set(req, (stores = {}))
getInitialState(id)
)
// save a reference to the initial state
- // TODO: this implies that replacing the store cannot be done by the user because we are relying on the object reference
+ // TODO: this implies that replacing the store cannot be done by the user on the server
setInitialState(store)
if (isClient) useStoreDevtools(store)
}
{
"compilerOptions": {
+ "allowJs": true,
"target": "esnext",
"module": "esnext",
"noEmit": true,
"rootDir": ".",
"baseUrl": "."
},
- "include": ["src/**/*.ts", "__tests__/**/**.ts"]
+ "include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/**.ts"]
}