Skip to content
Permalink
Browse files

feat(types): adding logger type for logger plugin (#1853)

`createLogger` takes in logger option which by default is console but
can be overridden with own logger. Here we addd `Logger` interface
for `logger` options params which expects log method to
be implemented.

Co-authored-by: Thomas Truong <ttruong@factset.com>
  • Loading branch information
itomtom and Thomas Truong committed Oct 23, 2020
1 parent 6734ac5 commit cb3198d5998bdb11ef05dfa5ef98d5c5fa873089
Showing with 14 additions and 1 deletion.
  1. +6 −0 types/logger.d.ts
  2. +8 −1 types/test/index.ts
@@ -1,5 +1,10 @@
import { Payload, Plugin } from "./index";

interface Logger extends Partial<Pick<Console, 'groupCollapsed' | 'group' | 'groupEnd'>> {
log(message: string, colour: string, action: any): void;
log(message: string): void;
}

export interface LoggerOption<S> {
collapsed?: boolean;
filter?: <P extends Payload>(mutation: P, stateBefore: S, stateAfter: S) => boolean;
@@ -9,6 +14,7 @@ export interface LoggerOption<S> {
actionTransformer?: <P extends Payload>(action: P) => any;
logMutations?: boolean;
logActions?: boolean;
logger?: Logger;
}

export default function createLogger<S>(option?: LoggerOption<S>): Plugin<S>;
@@ -437,10 +437,17 @@ namespace Plugins {
});
}

class MyLogger {
log(message: string) {
console.log(message);
}
}

const logger = Vuex.createLogger<{ value: number }>({
collapsed: true,
transformer: state => state.value,
mutationTransformer: (mutation: { type: string }) => mutation.type
mutationTransformer: (mutation: { type: string }) => mutation.type,
logger: new MyLogger()
});

const store = new Vuex.Store<{ value: number }>({

0 comments on commit cb3198d

Please sign in to comment.