@@ -63,6 +63,7 @@ function deepCopy (obj, cache) {
63
63
function createLogger ( ref ) {
64
64
if ( ref === void 0 ) ref = { } ;
65
65
var collapsed = ref . collapsed ; if ( collapsed === void 0 ) collapsed = true ;
66
+ var filter = ref . filter ; if ( filter === void 0 ) filter = function ( mutation , stateBefore , stateAfter ) { return true ; } ;
66
67
var transformer = ref . transformer ; if ( transformer === void 0 ) transformer = function ( state ) { return state ; } ;
67
68
var mutationTransformer = ref . mutationTransformer ; if ( mutationTransformer === void 0 ) mutationTransformer = function ( mut ) { return mut ; } ;
68
69
@@ -74,29 +75,32 @@ function createLogger (ref) {
74
75
return
75
76
}
76
77
var nextState = deepCopy ( state ) ;
77
- var time = new Date ( ) ;
78
- var formattedTime = " @ " + ( pad ( time . getHours ( ) , 2 ) ) + ":" + ( pad ( time . getMinutes ( ) , 2 ) ) + ":" + ( pad ( time . getSeconds ( ) , 2 ) ) + "." + ( pad ( time . getMilliseconds ( ) , 3 ) ) ;
79
- var formattedMutation = mutationTransformer ( mutation ) ;
80
- var message = "mutation " + ( mutation . type ) + formattedTime ;
81
- var startMessage = collapsed
82
- ? console . groupCollapsed
83
- : console . group ;
84
-
85
- // render
86
- try {
87
- startMessage . call ( console , message ) ;
88
- } catch ( e ) {
89
- console . log ( message ) ;
90
- }
91
-
92
- console . log ( '%c prev state' , 'color: #9E9E9E; font-weight: bold' , transformer ( prevState ) ) ;
93
- console . log ( '%c mutation' , 'color: #03A9F4; font-weight: bold' , formattedMutation ) ;
94
- console . log ( '%c next state' , 'color: #4CAF50; font-weight: bold' , transformer ( nextState ) ) ;
95
78
96
- try {
97
- console . groupEnd ( ) ;
98
- } catch ( e ) {
99
- console . log ( '—— log end ——' ) ;
79
+ if ( filter ( mutation , prevState , nextState ) ) {
80
+ var time = new Date ( ) ;
81
+ var formattedTime = " @ " + ( pad ( time . getHours ( ) , 2 ) ) + ":" + ( pad ( time . getMinutes ( ) , 2 ) ) + ":" + ( pad ( time . getSeconds ( ) , 2 ) ) + "." + ( pad ( time . getMilliseconds ( ) , 3 ) ) ;
82
+ var formattedMutation = mutationTransformer ( mutation ) ;
83
+ var message = "mutation " + ( mutation . type ) + formattedTime ;
84
+ var startMessage = collapsed
85
+ ? console . groupCollapsed
86
+ : console . group ;
87
+
88
+ // render
89
+ try {
90
+ startMessage . call ( console , message ) ;
91
+ } catch ( e ) {
92
+ console . log ( message ) ;
93
+ }
94
+
95
+ console . log ( '%c prev state' , 'color: #9E9E9E; font-weight: bold' , transformer ( prevState ) ) ;
96
+ console . log ( '%c mutation' , 'color: #03A9F4; font-weight: bold' , formattedMutation ) ;
97
+ console . log ( '%c next state' , 'color: #4CAF50; font-weight: bold' , transformer ( nextState ) ) ;
98
+
99
+ try {
100
+ console . groupEnd ( ) ;
101
+ } catch ( e ) {
102
+ console . log ( '—— log end ——' ) ;
103
+ }
100
104
}
101
105
102
106
prevState = nextState ;
0 commit comments