direct-vuex
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -21,3 +21,4 @@ { | ||
"typescript.preferences.importModuleSpecifier": "relative", | ||
"typescript.preferences.quoteStyle": "double" | ||
"typescript.preferences.quoteStyle": "double", | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
{ | ||
"name": "direct-vuex", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Use and implement your Vuex store with TypeScript types. Compatible with the Vue 3 composition API.", | ||
@@ -26,5 +26,5 @@ "author": "Paleo", | ||
"rimraf": "^3.0.0", | ||
"ts-jest": "^24.1.0", | ||
"ts-jest": "^24.2.0", | ||
"tslint": "^5.20.1", | ||
"typescript": "^3.7.2", | ||
"typescript": "^3.7.3", | ||
"vue": "*", | ||
@@ -31,0 +31,0 @@ "vuex": "^3.1.2" |
@@ -150,3 +150,3 @@ # direct-vuex | ||
### A Limitation on how to declare a State | ||
### A limitation on how to declare a State | ||
@@ -166,3 +166,3 @@ In store and module options, the `state` property shouldn't be declared with the ES6 method syntax. | ||
```ts | ||
state: function (): Mod1State { p1: string } | ||
state: function (): Mod1State { return { p1: string } } | ||
``` | ||
@@ -173,3 +173,3 @@ | ||
```ts | ||
state(): Mod1State { p1: string } | ||
state(): Mod1State { return { p1: string } } | ||
``` | ||
@@ -176,0 +176,0 @@ |
import Vuex, { ActionContext, Store } from "vuex" | ||
import { ActionsImpl, GettersImpl, ModuleOptions, ModulesImpl, MutationsImpl, StoreOptions, StoreOrModuleOptions, WithState } from "../types" | ||
import { ActionsImpl, GettersImpl, ModuleOptions, ModulesImpl, MutationsImpl, StateOf, StoreOptions, StoreOrModuleOptions, WithOptionalState } from "../types" | ||
import { CreatedStore, ToDirectStore, VuexStore } from "../types/direct-types" | ||
export function createDirectStore<O extends WithState, S = O["state"]>(options: O & StoreOptions<S>): CreatedStore<O> { | ||
export function createDirectStore< | ||
O extends WithOptionalState, | ||
S = StateOf<O> | ||
>(options: O & StoreOptions<S>): CreatedStore<O> { | ||
const original = new Vuex.Store(options as any) as VuexStore<O> | ||
@@ -28,3 +31,6 @@ | ||
export function createModule<O extends WithState, S = O["state"]>(options: O & ModuleOptions<S>): O { | ||
export function createModule< | ||
O extends WithOptionalState, | ||
S = StateOf<O> | ||
>(options: O & ModuleOptions<S>): O { | ||
return options | ||
@@ -31,0 +37,0 @@ } |
import Vue from "vue" | ||
import Vuex from "vuex" | ||
import { createDirectStore } from "../src/direct-vuex" | ||
import { createDirectStore, createModule } from "../src/direct-vuex" | ||
@@ -10,3 +10,3 @@ Vue.use(Vuex) | ||
test("Use 'dispatch' and 'rootDispatch' from action implementation", async () => { | ||
const mod1 = { | ||
const mod1 = createModule({ | ||
namespaced: true, | ||
@@ -27,3 +27,3 @@ actions: { | ||
} | ||
} as const | ||
}) | ||
const mod1ActionContext = (context: any) => moduleActionContext(context, mod1) | ||
@@ -44,3 +44,3 @@ | ||
} | ||
} as const) | ||
}) | ||
@@ -47,0 +47,0 @@ await store.dispatch.a1({ p1: "abc" }) |
@@ -12,3 +12,3 @@ import Vue from "vue" | ||
actions: { | ||
a1: async (context: any, payload: { p1: string }) => payload.p1 | ||
a1: async (context, payload: { p1: string }) => payload.p1 | ||
}, | ||
@@ -19,7 +19,7 @@ modules: { | ||
actions: { | ||
a2: async (context: any, payload: { p2: number }) => payload.p2 | ||
a2: async (context, payload: { p2: number }) => payload.p2 | ||
} | ||
} | ||
} | ||
} as const) | ||
}) | ||
@@ -36,3 +36,3 @@ const p1: string = await store.dispatch.a1({ p1: "abc" }) | ||
mutations: { | ||
mu1: (state: any, payload: { p1: string }) => { } | ||
mu1: (state, payload: { p1: string }) => { } | ||
}, | ||
@@ -43,7 +43,7 @@ modules: { | ||
mutations: { | ||
mu2: (state: any, payload: { p2: number }) => { } | ||
mu2: (state, payload: { p2: number }) => { } | ||
} | ||
} | ||
} | ||
} as const) | ||
}) | ||
@@ -57,3 +57,3 @@ store.commit.mu1({ p1: "abc" }) | ||
getters: { | ||
g1: (state: any) => "abc" | ||
g1: (state) => "abc" | ||
}, | ||
@@ -68,3 +68,3 @@ modules: { | ||
} | ||
} as const) | ||
}) | ||
@@ -71,0 +71,0 @@ const g1: string = store.getters.g1 |
@@ -22,3 +22,3 @@ import Vue from "vue" | ||
} | ||
} as const) | ||
}) | ||
@@ -44,3 +44,3 @@ const p1: string = await store.dispatch.a1({ p1: "abc" }) | ||
} | ||
} as const) | ||
}) | ||
@@ -67,3 +67,3 @@ const p1: string = await store.dispatch.a1({ p1: "abc" }) | ||
} | ||
} as const) | ||
}) | ||
@@ -87,3 +87,3 @@ store.commit.mu1({ p1: "abc" }) | ||
} | ||
} as const) | ||
}) | ||
@@ -90,0 +90,0 @@ const g1: string = store.getters.g1 |
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"target": "es2015", | ||
@@ -6,0 +5,0 @@ "module": "commonjs", |
@@ -121,3 +121,3 @@ import { ActionContext, Store } from "vuex" | ||
type OrEmpty<T> = T extends {} ? T : {} | ||
export type OrEmpty<T> = T extends {} ? T : {} | ||
@@ -124,0 +124,0 @@ type UnionToIntersection<U> = |
import { ActionContext } from "vuex" | ||
import { CreatedStore } from "./direct-types" | ||
export function createDirectStore<O extends WithState, S = O["state"]>(options: O & StoreOptions<S>): CreatedStore<O> | ||
export function createModule<O extends WithState, S = O["state"]>(options: O & ModuleOptions<S>): O | ||
export function createDirectStore< | ||
O extends WithOptionalState, | ||
S = StateOf<O> | ||
>(options: O & StoreOptions<S>): CreatedStore<O> | ||
export function createModule< | ||
O extends WithOptionalState, | ||
S = StateOf<O> | ||
>(options: O & ModuleOptions<S>): O | ||
export type WithOptionalState = { state: StateDeclaration } | {} | ||
export type StateOf<O> = O extends { state: StateDeclaration } ? O["state"] : {} | ||
type StateDeclaration = any | (() => any) | ||
export function createModules<S>(): (<T>(modules: T & ModulesImpl<S>) => T) | ||
@@ -12,6 +23,2 @@ export function createGetters<S>(): (<T>(getters: T & GettersImpl<S>) => T) | ||
export interface WithState { | ||
state?: any | (() => any) | ||
} | ||
/* | ||
@@ -22,3 +29,3 @@ * Types for Vuex Store Options | ||
export interface StoreOrModuleOptions<S = any> { | ||
state?: (() => S) | S, | ||
state?: S extends object ? ((() => S) | S) : never, | ||
getters?: GettersImpl<S> | ||
@@ -25,0 +32,0 @@ mutations?: MutationsImpl<S> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40766
816