Skip to content

Commit

Permalink
feat: include logger plugin to the core export (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking authored Jun 26, 2020
1 parent 3bd49b7 commit 04e2bd8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/index.cjs.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,5 +10,6 @@ export default {
mapMutations,
mapGetters,
mapActions,
createNamespacedHelpers
createNamespacedHelpers,
createLogger
}
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,7 +10,8 @@ export default {
mapMutations,
mapGetters,
mapActions,
createNamespacedHelpers
createNamespacedHelpers,
createLogger
}

export {
Expand All @@ -19,5 +21,6 @@ export {
mapMutations,
mapGetters,
mapActions,
createNamespacedHelpers
createNamespacedHelpers,
createLogger
}
5 changes: 5 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<S> {
constructor(options: StoreOptions<S>);
Expand Down Expand Up @@ -147,6 +149,8 @@ export interface ModuleTree<R> {
[key: string]: Module<any, R>;
}

export { createLogger }

declare const _default: {
Store: typeof Store;
install: typeof install;
Expand All @@ -155,5 +159,6 @@ declare const _default: {
mapGetters: typeof mapGetters,
mapActions: typeof mapActions,
createNamespacedHelpers: typeof createNamespacedHelpers,
createLogger: typeof createLogger
};
export default _default;
14 changes: 14 additions & 0 deletions types/logger.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Payload, Plugin } from "./index";

export interface LoggerOption<S> {
collapsed?: boolean;
filter?: <P extends Payload>(mutation: P, stateBefore: S, stateAfter: S) => boolean;
transformer?: (state: S) => any;
mutationTransformer?: <P extends Payload>(mutation: P) => any;
actionFilter?: <P extends Payload>(action: P, state: S) => boolean;
actionTransformer?: <P extends Payload>(action: P) => any;
logMutations?: boolean;
logActions?: boolean;
}

export default function createLogger<S>(option?: LoggerOption<S>): Plugin<S>;
3 changes: 1 addition & 2 deletions types/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Vue from "vue";
import * as Vuex from "../index";
import createLogger from "../../dist/logger";

Vue.use(Vuex);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04e2bd8

Please sign in to comment.