Skip to content

Commit

Permalink
feat(types): adding logger type for logger plugin
Browse files Browse the repository at this point in the history
* createLogger options takes in logger which by default is console but
can be overridden with own logger.
* Adding Ilogger for logger options params which expects log method to
be implemented
  • Loading branch information
Thomas Truong committed Oct 18, 2020
1 parent 6734ac5 commit 73a8ddd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions types/logger.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Payload, Plugin } from "./index";

interface ILogger extends Partial<Console> {
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;
Expand All @@ -9,6 +14,7 @@ export interface LoggerOption<S> {
actionTransformer?: <P extends Payload>(action: P) => any;
logMutations?: boolean;
logActions?: boolean;
logger?: ILogger;
}

export default function createLogger<S>(option?: LoggerOption<S>): Plugin<S>;
9 changes: 8 additions & 1 deletion types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>({
Expand Down

0 comments on commit 73a8ddd

Please sign in to comment.