Skip to content

Commit 1c628e6

Browse files
patinthehatPatrick
authored andcommitted
add support for filtering displayed state props when tracking state
1 parent 5f1bac1 commit 1c628e6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/shared/helpers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PackageInfo } from './PackageInfo';
2+
import multimatch from 'multimatch';
23

34
// @ts-ignore
45
export const createPackageMetaProperty = obj => {
@@ -25,3 +26,15 @@ export const encodeHtmlEntities = (str: string) => {
2526

2627
return str.replace(regex, m => `&${escapeChars[m]};`);
2728
};
29+
30+
export const filterObjectByKeys = (obj: any, includeKeyPatterns: string[]) => {
31+
const result: any = {};
32+
33+
Object.keys(obj).forEach(key => {
34+
multimatch(key, includeKeyPatterns).forEach(match => {
35+
result[match] = obj[match];
36+
});
37+
});
38+
39+
return result;
40+
};

src/vuex/VuexPlugin.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* eslint-disable no-unused-vars */
22

3+
import { filterObjectByKeys } from '../shared/helpers';
34
import { ray } from '../shared/VueRay';
45

56
export let vuexStateRay: any = null;
67

78
class VuexState {
89
public state: any;
910

10-
constructor(state: any) {
11-
this.state = state;
11+
constructor(state: any, options: RayVuexPluginOptions = {}) {
12+
this.state = filterObjectByKeys(Object.assign({}, state), options.trackingOptions?.propNames ?? ['one']);
1213
}
1314
}
1415

@@ -26,6 +27,10 @@ export interface RayVuexPluginOptions {
2627
logActions?: boolean;
2728
loggedMutationColor?: RayVuexPluginLogColor;
2829
loggedActionColor?: RayVuexPluginLogColor;
30+
trackingOptions?: {
31+
moduleNames?: string[];
32+
propNames?: string[];
33+
};
2934
}
3035

3136
const DefaultVuexPluginOptions: RayVuexPluginOptions = {
@@ -34,6 +39,10 @@ const DefaultVuexPluginOptions: RayVuexPluginOptions = {
3439
logActions: false,
3540
loggedMutationColor: 'none',
3641
loggedActionColor: 'none',
42+
trackingOptions: {
43+
moduleNames: ['*'],
44+
propNames: ['*'],
45+
},
3746
};
3847

3948
const decorateEventType = (name: RayVuexPluginEventType, color: string) => {
@@ -78,7 +87,7 @@ export const VuexPlugin = (
7887
vuexStateRay = rayInstance();
7988
}
8089

81-
vuexStateRay = vuexStateRay.send(new VuexState(copiedState));
90+
vuexStateRay = vuexStateRay.send(new VuexState(copiedState, options));
8291
});
8392
}
8493

0 commit comments

Comments
 (0)