Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include logger plugin to the core export #1783

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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