From 5a745863a95e6b68fb9f85771aafbcacc9874ca8 Mon Sep 17 00:00:00 2001 From: Thomas Truong Date: Sun, 18 Oct 2020 15:38:13 +0100 Subject: [PATCH] feat(types): adding logger type for logger plugin * 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 --- types/logger.d.ts | 6 ++++++ types/test/index.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/logger.d.ts b/types/logger.d.ts index 873af7f0d2..f8cf106350 100644 --- a/types/logger.d.ts +++ b/types/logger.d.ts @@ -1,5 +1,10 @@ import { Payload, Plugin } from "./index"; +interface Logger extends Partial> { + log(message: string, colour: string, action: any): void; + log(message: string): void; +} + export interface LoggerOption { collapsed?: boolean; filter?:

(mutation: P, stateBefore: S, stateAfter: S) => boolean; @@ -9,6 +14,7 @@ export interface LoggerOption { actionTransformer?:

(action: P) => any; logMutations?: boolean; logActions?: boolean; + logger?: Logger; } export default function createLogger(option?: LoggerOption): Plugin; diff --git a/types/test/index.ts b/types/test/index.ts index c801264a84..32d5ec2c6d 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -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 }>({