direct-vuex
Advanced tools
Comparing version 0.2.6 to 0.3.0
@@ -6,4 +6,3 @@ "use strict"; | ||
const original = new vuex_1.default.Store(options); | ||
return { | ||
original, | ||
const direct = { | ||
get state() { | ||
@@ -14,4 +13,7 @@ return original.state; | ||
commit: commitFromOptions({}, options, original), | ||
dispatch: dispatchFromOptions({}, options, original) | ||
dispatch: dispatchFromOptions({}, options, original), | ||
original | ||
}; | ||
original.direct = direct; | ||
return direct; | ||
} | ||
@@ -18,0 +20,0 @@ exports.createDirectStore = createDirectStore; |
{ | ||
"name": "direct-vuex", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"description": "Just Vuex with typing. Compatible with the Vue 3 composition API.", | ||
@@ -5,0 +5,0 @@ "author": "Paleo", |
@@ -25,6 +25,15 @@ # direct-vuex | ||
export default createDirectStore({ | ||
const store = createDirectStore({ | ||
// … store implementation here … | ||
} as const) | ||
export default store | ||
export type AppStore = typeof store | ||
declare module "vuex" { | ||
interface Store<S> { | ||
direct: AppStore | ||
} | ||
} | ||
The classic Vuex store is still accessible through the `store.original` property. We need it to initialize the Vue application: | ||
@@ -42,4 +51,8 @@ | ||
From a component, import the store. | ||
From a component, the direct store is accessible through the `direct` property of the classic store: | ||
const store = this.$store.direct | ||
Or, you can just import it: | ||
import store from "./store" | ||
@@ -59,4 +72,4 @@ | ||
store.getters.myModule.myGetter; | ||
store.commit.myModule.myMutation(myPayload); | ||
store.getters.myModule.myGetter | ||
store.commit.myModule.myMutation(myPayload) | ||
@@ -63,0 +76,0 @@ Notice: The underlying Vuex store can be used simultaneously if you wish, through the injected `this.$store` or `store.original`. |
import Vuex, { Store } from "vuex" | ||
import { ActionsImpl, GettersImpl, MutationsImpl, StoreOptions, StoreOrModuleOptions } from "../types" | ||
import { ToDirectStore } from "../types/direct-types" | ||
import { ToDirectStore, VuexStore } from "../types/direct-types" | ||
export function createDirectStore<O extends StoreOptions>(options: O): ToDirectStore<O> { | ||
const original = new Vuex.Store(options) | ||
const original = new Vuex.Store(options) as VuexStore<O> | ||
return { | ||
original, | ||
const direct = { | ||
get state() { | ||
@@ -15,4 +14,8 @@ return original.state | ||
commit: commitFromOptions({}, options, original), | ||
dispatch: dispatchFromOptions({}, options, original) | ||
dispatch: dispatchFromOptions({}, options, original), | ||
original | ||
} | ||
original.direct = direct | ||
return direct | ||
} | ||
@@ -19,0 +22,0 @@ |
@@ -5,3 +5,2 @@ import { Store } from "vuex" | ||
export type ToDirectStore<O extends StoreOptions> = ToFlatStore<{ | ||
original: Store<DirectState<O>>, | ||
readonly state: DirectState<O> | ||
@@ -11,4 +10,9 @@ getters: DirectGetters<O> | ||
dispatch: DirectActions<O> | ||
original: VuexStore<O> | ||
}> | ||
export type VuexStore<O extends StoreOptions> = Store<ToFlatStore<DirectState<O>>> & { | ||
direct: ToDirectStore<O> | ||
} | ||
// State | ||
@@ -24,3 +28,3 @@ | ||
type ToStateObj<T> = T extends (() => any) ? ReturnType<T> : T; | ||
type ToStateObj<T> = T extends (() => any) ? ReturnType<T> : T | ||
@@ -27,0 +31,0 @@ // Getters |
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
23087
411
84