vuex-composition-helpers
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,6 +0,9 @@ | ||
import { computed } from 'vue'; | ||
import { computed, readonly } from 'vue'; | ||
import { computedGetter, getAction, getMutation, getStoreFromInstance, useMapping } from './util'; | ||
function computedState(store, namespace, prop) { | ||
let module = namespace.split('/').reduce((module, key) => module[key], store.state); | ||
return computed(() => module[prop]); | ||
return computed(() => { | ||
const val = module[prop]; | ||
return typeof val === 'object' ? readonly(val) : val; | ||
}); | ||
} | ||
@@ -7,0 +10,0 @@ export function useNamespacedState(storeOrNamespace, namespaceOrMap, map) { |
import { Store } from 'vuex/types'; | ||
import { ExtractGetterTypes, ExtractTypes, KnownKeys, RefTypes } from './util'; | ||
import { ExtractGetterTypes, ExtractTypes, KnownKeys, ComputedRefTypes } from './util'; | ||
export declare function useStore<TState = any>(): Store<TState>; | ||
export declare function useState<TState = any>(storeOrMap: Store<TState> | KnownKeys<TState>[], map?: KnownKeys<TState>[]): RefTypes<TState>; | ||
export declare function useState<TState = any>(storeOrMap: Store<TState> | KnownKeys<TState>[], map?: KnownKeys<TState>[]): ComputedRefTypes<TState>; | ||
export declare function useGetters<TGetters = any>(storeOrMap: Store<any> | KnownKeys<TGetters>[], map?: KnownKeys<TGetters>[]): ExtractGetterTypes<TGetters>; | ||
export declare function useMutations<TMutations = any>(storeOrMap: Store<any> | KnownKeys<TMutations>[], map?: KnownKeys<TMutations>[]): ExtractTypes<TMutations, Function>; | ||
export declare function useActions<TActions = any>(storeOrMap: Store<any> | KnownKeys<TActions>[], map?: KnownKeys<TActions>[]): ExtractTypes<TActions, Function>; |
@@ -1,5 +0,5 @@ | ||
import { KnownKeys, RefTypes, ExtractTypes, ExtractGetterTypes } from './util'; | ||
import { KnownKeys, ComputedRefTypes, ExtractTypes, ExtractGetterTypes } from './util'; | ||
import { Store } from 'vuex'; | ||
export declare type Nullish = null | undefined; | ||
export declare function useNamespacedState<TState = any>(storeOrNamespace: Store<any> | string | Nullish, namespaceOrMap: string | KnownKeys<TState>[], map?: KnownKeys<TState>[]): RefTypes<TState>; | ||
export declare function useNamespacedState<TState = any>(storeOrNamespace: Store<any> | string | Nullish, namespaceOrMap: string | KnownKeys<TState>[], map?: KnownKeys<TState>[]): ComputedRefTypes<TState>; | ||
export declare function useNamespacedMutations<TMutations = any>(storeOrNamespace: Store<any> | string | Nullish, namespaceOrMap: string | KnownKeys<TMutations>[], map?: KnownKeys<TMutations>[]): ExtractTypes<TMutations, Function>; | ||
@@ -9,3 +9,3 @@ export declare function useNamespacedActions<TActions = any>(storeOrNamespace: Store<any> | string | Nullish, namespaceOrMap: string | KnownKeys<TActions>[], map?: KnownKeys<TActions>[]): ExtractTypes<TActions, Function>; | ||
export declare function createNamespacedHelpers<TState = any, TGetters = any, TActions = any, TMutations = any>(storeOrNamespace: Store<any> | string, namespace?: string): { | ||
useState: (map?: KnownKeys<TState>[]) => RefTypes<TState>; | ||
useState: (map?: KnownKeys<TState>[]) => ComputedRefTypes<TState>; | ||
useGetters: (map?: KnownKeys<TGetters>[]) => ExtractGetterTypes<TGetters>; | ||
@@ -12,0 +12,0 @@ useMutations: (map?: KnownKeys<TMutations>[]) => ExtractTypes<TMutations, Function>; |
@@ -1,2 +0,2 @@ | ||
import { Ref } from 'vue'; | ||
import { ComputedRef, DeepReadonly } from 'vue'; | ||
import { Store } from 'vuex/types'; | ||
@@ -10,3 +10,3 @@ declare type OmitFirstArg<F, TReturn> = F extends (x: any, ...args: infer P) => any ? (...args: P) => TReturn : never; | ||
export declare type ExtractGetterTypes<O> = { | ||
readonly [K in keyof O]: Ref<InferGetterType<O[K]>>; | ||
readonly [K in keyof O]: ComputedRef<DeepReadonly<InferGetterType<O[K]>>>; | ||
}; | ||
@@ -18,6 +18,6 @@ export declare type KnownKeys<T> = { | ||
} ? U : never; | ||
export declare type RefTypes<T> = { | ||
readonly [Key in keyof T]: Ref<T[Key]>; | ||
export declare type ComputedRefTypes<T> = { | ||
readonly [Key in keyof T]: ComputedRef<DeepReadonly<T[Key]>>; | ||
}; | ||
export declare function computedGetter<T = any>(store: any, prop: string): import("vue").ComputedRef<T>; | ||
export declare function computedGetter<T = any>(store: any, prop: string): ComputedRef<T>; | ||
export declare function getMutation(store: any, mutation: string): Function; | ||
@@ -24,0 +24,0 @@ export declare function getAction(store: any, action: string): Function; |
export declare function wrapStore(store: any): { | ||
createNamespacedHelpers: (namespace?: string | undefined) => { | ||
useState: (map?: unknown[] | undefined) => import("./util").RefTypes<unknown>; | ||
useState: (map?: unknown[] | undefined) => import("./util").ComputedRefTypes<unknown>; | ||
useGetters: (map?: unknown[] | undefined) => import("./util").ExtractGetterTypes<unknown>; | ||
@@ -11,3 +11,3 @@ useMutations: (map?: unknown[] | undefined) => import("./util").ExtractTypes<unknown, Function>; | ||
useMutations: (map?: unknown[] | undefined) => import("./util").ExtractTypes<unknown, Function>; | ||
useState: (map?: unknown[] | undefined) => import("./util").RefTypes<unknown>; | ||
useState: (map?: unknown[] | undefined) => import("./util").ComputedRefTypes<unknown>; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { computed, getCurrentInstance } from 'vue'; | ||
import { computed, readonly, getCurrentInstance } from 'vue'; | ||
function runCB(cb, store, namespace, prop) { | ||
@@ -26,3 +26,6 @@ if (cb.length === 3) { // choose which signature to pass to cb function | ||
export function computedGetter(store, prop) { | ||
return computed(() => store.getters[prop]); | ||
return computed(() => { | ||
const val = store.getters[prop]; | ||
return typeof val === 'object' ? readonly(val) : val; | ||
}); | ||
} | ||
@@ -29,0 +32,0 @@ export function getMutation(store, mutation) { |
{ | ||
"name": "vuex-composition-helpers", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Helpers to use Vuex store form Vue Composition API", | ||
@@ -5,0 +5,0 @@ "author": "David Meir-Levy <davidmeirlevy@gmail.com>", |
import {Store} from 'vuex/types'; | ||
import {computed, readonly} from 'vue'; | ||
import {computedGetter, getAction, getMutation, getStoreFromInstance, useMapping, ExtractGetterTypes, ExtractTypes, KnownKeys, RefTypes} from './util'; | ||
import {computedGetter, getAction, getMutation, getStoreFromInstance, useMapping, ExtractGetterTypes, ExtractTypes, KnownKeys, ComputedRefTypes} from './util'; | ||
@@ -16,3 +16,3 @@ function computedState(store: any, prop: string) { | ||
export function useState<TState = any>(storeOrMap: Store<TState> | KnownKeys<TState>[], map?: KnownKeys<TState>[]): RefTypes<TState> { | ||
export function useState<TState = any>(storeOrMap: Store<TState> | KnownKeys<TState>[], map?: KnownKeys<TState>[]): ComputedRefTypes<TState> { | ||
let store = storeOrMap; | ||
@@ -19,0 +19,0 @@ |
@@ -1,3 +0,3 @@ | ||
import {computed} from 'vue'; | ||
import {computedGetter, getAction, getMutation, getStoreFromInstance, useMapping, KnownKeys, RefTypes, ExtractTypes, ExtractGetterTypes} from './util'; | ||
import {computed, readonly} from 'vue'; | ||
import {computedGetter, getAction, getMutation, getStoreFromInstance, useMapping, KnownKeys, ComputedRefTypes, ExtractTypes, ExtractGetterTypes} from './util'; | ||
import {Store} from 'vuex'; | ||
@@ -9,6 +9,9 @@ | ||
let module = namespace.split('/').reduce((module, key) => module[key], store.state) | ||
return computed(() => module[prop]) | ||
return computed(() => { | ||
const val = module[prop]; | ||
return typeof val === 'object' ? readonly(val) : val | ||
}); | ||
} | ||
export function useNamespacedState<TState = any>(storeOrNamespace: Store<any> | string | Nullish, namespaceOrMap: string | KnownKeys<TState>[], map?: KnownKeys<TState>[]): RefTypes<TState> { | ||
export function useNamespacedState<TState = any>(storeOrNamespace: Store<any> | string | Nullish, namespaceOrMap: string | KnownKeys<TState>[], map?: KnownKeys<TState>[]): ComputedRefTypes<TState> { | ||
let store: Store<any>, namespace: string; | ||
@@ -70,3 +73,3 @@ | ||
export function createNamespacedHelpers<TState = any, TGetters = any, TActions = any, TMutations = any>(storeOrNamespace: Store<any> | string, namespace?: string):{ | ||
useState: (map?: KnownKeys<TState>[]) => RefTypes<TState>; | ||
useState: (map?: KnownKeys<TState>[]) => ComputedRefTypes<TState>; | ||
useGetters: (map?: KnownKeys<TGetters>[]) => ExtractGetterTypes<TGetters>; | ||
@@ -73,0 +76,0 @@ useMutations: (map?: KnownKeys<TMutations>[]) => ExtractTypes<TMutations, Function>; |
@@ -1,2 +0,2 @@ | ||
import {computed, getCurrentInstance, Ref} from 'vue'; | ||
import {computed, readonly, getCurrentInstance, ComputedRef, DeepReadonly} from 'vue'; | ||
import {Store} from 'vuex/types'; | ||
@@ -26,3 +26,3 @@ | ||
export declare type ExtractGetterTypes<O> = { | ||
readonly [K in keyof O]: Ref<InferGetterType<O[K]>>; | ||
readonly [K in keyof O]: ComputedRef<DeepReadonly<InferGetterType<O[K]>>> | ||
}; | ||
@@ -42,4 +42,4 @@ | ||
export declare type RefTypes<T> = { | ||
readonly [Key in keyof T]: Ref<T[Key]> | ||
export declare type ComputedRefTypes<T> = { | ||
readonly [Key in keyof T]: ComputedRef<DeepReadonly<T[Key]>> | ||
} | ||
@@ -73,3 +73,6 @@ | ||
export function computedGetter<T = any>(store: any, prop: string) { | ||
return computed<T>(() => store.getters[prop]); | ||
return computed<T>(() => { | ||
const val = store.getters[prop]; | ||
return typeof val === 'object' ? readonly(val) : val | ||
}); | ||
} | ||
@@ -76,0 +79,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36737
527