direct-vuex
Advanced tools
Comparing version 0.8.4 to 0.8.5
@@ -111,7 +111,7 @@ "use strict"; | ||
function getModuleActionContext(originalContext, options, store) { | ||
let context = actionContexts.get(originalContext.dispatch); | ||
let context = actionContexts.get(originalContext.state); | ||
if (!context) { | ||
context = createModuleActionContext(options, originalContext, store); | ||
if (originalContext.dispatch) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.dispatch, context); | ||
if (originalContext.state) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.state, context); | ||
} | ||
@@ -138,7 +138,7 @@ return context; | ||
return (originalContext) => { | ||
let context = actionContexts.get(originalContext.dispatch); | ||
let context = actionContexts.get(originalContext.state); | ||
if (!context) { | ||
context = createRootActionContext(originalContext, store); | ||
if (originalContext.dispatch) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.dispatch, context); | ||
if (originalContext.state) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.state, context); | ||
} | ||
@@ -145,0 +145,0 @@ return context; |
{ | ||
"name": "direct-vuex", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "Use and implement your Vuex store with TypeScript types. Compatible with the Vue 3 composition API.", | ||
@@ -5,0 +5,0 @@ "author": "Paleo", |
@@ -132,9 +132,9 @@ # direct-vuex | ||
Direct-vuex provides several useful helpers for implementation of the store. They are all optional. However, if you want to keep your classic implementation of a Vuex Store, then direct-vuex needs to infer the literal type of the `namespaced` property. You can write `namespaced: true as true` or append `as const` where there is a `namespaced` property. But you don't need to worry about that if you use the helpers described in the following sections. | ||
Direct-vuex provides several useful helpers for implementation of the store. They are all optional. However, if you want to keep your classic implementation of a Vuex Store, then direct-vuex needs to infer the literal type of the `namespaced` property. You can write `namespaced: true as true` or append `as const` where there is a `namespaced` property. But you don't need to worry about that if you use `createModule`. | ||
### In a Vuex Module | ||
Like [the function `createComponent`](https://vue-composition-api-rfc.netlify.com/api.html#createcomponent) from the composition API, the function `createModule` is provided solely for type inference. It is a no-op behavior-wise. It expects a module implementation and returns the argument as-is. | ||
The function `createModule` is provided solely for type inference. It is a no-op behavior-wise. It expects a module implementation and returns the argument as-is. This behaviour is similar to (and inspired from) the [function `createComponent`](https://vue-composition-api-rfc.netlify.com/api.html#createcomponent) from the composition API. | ||
The generated function `moduleActionContext` is a factory for creating a function `mod1ActionContext`, which converts the injected action `context` to the direct-vuex one. | ||
The generated function `moduleActionContext` is a factory for creating a function `mod1ActionContext`, which converts the injected action context to the direct-vuex one. | ||
@@ -185,3 +185,3 @@ Here is how to use `createModule` and `moduleActionContext`: | ||
The generated function `rootActionContext` converts the injected action `context` to the direct-vuex one, at the root level (not in a module). | ||
The generated function `rootActionContext` converts the injected action context to the direct-vuex one, at the root level (not in a module). | ||
@@ -188,0 +188,0 @@ ```ts |
@@ -164,7 +164,7 @@ import Vuex, { ActionContext, Store } from "vuex" | ||
): any { | ||
let context = actionContexts.get(originalContext.dispatch) | ||
let context = actionContexts.get(originalContext.state) | ||
if (!context) { | ||
context = createModuleActionContext(options, originalContext, store) | ||
if (originalContext.dispatch) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.dispatch, context) | ||
if (originalContext.state) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.state, context) | ||
} | ||
@@ -197,7 +197,7 @@ return context | ||
return (originalContext: ActionContext<any, any>) => { | ||
let context = actionContexts.get(originalContext.dispatch) | ||
let context = actionContexts.get(originalContext.state) | ||
if (!context) { | ||
context = createRootActionContext(originalContext, store) | ||
if (originalContext.dispatch) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.dispatch, context) | ||
if (originalContext.state) // Can be 'undefined' in test units | ||
actionContexts.set(originalContext.state, context) | ||
} | ||
@@ -204,0 +204,0 @@ return context |
43030