Skip to content

Commit cb3198d

Browse files
itomtomThomas Truong
and
Thomas Truong
authored
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 <[email protected]>
1 parent 6734ac5 commit cb3198d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

types/logger.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Payload, Plugin } from "./index";
22

3+
interface Logger extends Partial<Pick<Console, 'groupCollapsed' | 'group' | 'groupEnd'>> {
4+
log(message: string, colour: string, action: any): void;
5+
log(message: string): void;
6+
}
7+
38
export interface LoggerOption<S> {
49
collapsed?: boolean;
510
filter?: <P extends Payload>(mutation: P, stateBefore: S, stateAfter: S) => boolean;
@@ -9,6 +14,7 @@ export interface LoggerOption<S> {
914
actionTransformer?: <P extends Payload>(action: P) => any;
1015
logMutations?: boolean;
1116
logActions?: boolean;
17+
logger?: Logger;
1218
}
1319

1420
export default function createLogger<S>(option?: LoggerOption<S>): Plugin<S>;

types/test/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,17 @@ namespace Plugins {
437437
});
438438
}
439439

440+
class MyLogger {
441+
log(message: string) {
442+
console.log(message);
443+
}
444+
}
445+
440446
const logger = Vuex.createLogger<{ value: number }>({
441447
collapsed: true,
442448
transformer: state => state.value,
443-
mutationTransformer: (mutation: { type: string }) => mutation.type
449+
mutationTransformer: (mutation: { type: string }) => mutation.type,
450+
logger: new MyLogger()
444451
});
445452

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

0 commit comments

Comments
 (0)