diff --git a/src/index.cjs.js b/src/index.cjs.js index ea28ccc1c..1f602d55e 100644 --- a/src/index.cjs.js +++ b/src/index.cjs.js @@ -1,5 +1,6 @@ import { Store, install } from './store' import { mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers } from './helpers' +import createLogger from './plugins/logger' export default { Store, @@ -9,5 +10,6 @@ export default { mapMutations, mapGetters, mapActions, - createNamespacedHelpers + createNamespacedHelpers, + createLogger } diff --git a/src/index.js b/src/index.js index e28e0cc3d..467c9da6c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import { Store, install } from './store' import { mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers } from './helpers' +import createLogger from './plugins/logger' export default { Store, @@ -9,7 +10,8 @@ export default { mapMutations, mapGetters, mapActions, - createNamespacedHelpers + createNamespacedHelpers, + createLogger } export { @@ -19,5 +21,6 @@ export { mapMutations, mapGetters, mapActions, - createNamespacedHelpers + createNamespacedHelpers, + createLogger } diff --git a/types/index.d.ts b/types/index.d.ts index 46b928af7..aeb69617f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4,8 +4,10 @@ import _Vue, { WatchOptions } from "vue"; import "./vue"; import { mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers } from "./helpers"; +import createLogger from "./logger"; export * from "./helpers"; +export * from "./logger"; export declare class Store { constructor(options: StoreOptions); @@ -147,6 +149,8 @@ export interface ModuleTree { [key: string]: Module; } +export { createLogger } + declare const _default: { Store: typeof Store; install: typeof install; @@ -155,5 +159,6 @@ declare const _default: { mapGetters: typeof mapGetters, mapActions: typeof mapActions, createNamespacedHelpers: typeof createNamespacedHelpers, + createLogger: typeof createLogger }; export default _default; diff --git a/types/logger.d.ts b/types/logger.d.ts new file mode 100644 index 000000000..873af7f0d --- /dev/null +++ b/types/logger.d.ts @@ -0,0 +1,14 @@ +import { Payload, Plugin } from "./index"; + +export interface LoggerOption { + collapsed?: boolean; + filter?:

(mutation: P, stateBefore: S, stateAfter: S) => boolean; + transformer?: (state: S) => any; + mutationTransformer?:

(mutation: P) => any; + actionFilter?:

(action: P, state: S) => boolean; + actionTransformer?:

(action: P) => any; + logMutations?: boolean; + logActions?: boolean; +} + +export default function createLogger(option?: LoggerOption): Plugin; diff --git a/types/test/index.ts b/types/test/index.ts index 92e138cb9..c801264a8 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -1,6 +1,5 @@ import Vue from "vue"; import * as Vuex from "../index"; -import createLogger from "../../dist/logger"; Vue.use(Vuex); @@ -438,7 +437,7 @@ namespace Plugins { }); } - const logger = createLogger<{ value: number }>({ + const logger = Vuex.createLogger<{ value: number }>({ collapsed: true, transformer: state => state.value, mutationTransformer: (mutation: { type: string }) => mutation.type