@@ -31,6 +31,13 @@ const styles = {
31
31
32
32
export const pad = ( num , maxLength ) => `${ num } ` . padStart ( 0 , maxLength ) ;
33
33
34
+ function omit ( keys , object ) {
35
+ return Object . entries ( object ) . reduce ( ( acc , [ key , value ] ) => {
36
+ acc [ key ] = keys . includes ( key ) ? '_ignored_' : value ;
37
+ return acc ;
38
+ } , { } ) ;
39
+ }
40
+
34
41
function formatTime ( time ) {
35
42
return `${ pad ( time . getHours ( ) , 2 ) } :${ pad ( time . getMinutes ( ) , 2 ) } :${ pad (
36
43
time . getSeconds ( ) ,
@@ -60,10 +67,11 @@ function renderDiff(diff) {
60
67
}
61
68
}
62
69
70
+ const logLevel = JSON . parse ( localStorage . getItem ( 'debug' ) ) ;
63
71
const isLoggingEnabled =
64
- process . env . NODE_ENV === 'development'
65
- ? localStorage . getItem ( 'debug' ) !== false
66
- : localStorage . getItem ( 'debug' ) === true ;
72
+ process . env . NODE_ENV === 'development' ? logLevel !== false : ! ! logLevel ;
73
+ const isDiffEnabled = logLevel === 'diff' ;
74
+ const diffIgnoreKeys = [ 'markupEditor' , 'queryEditor' , 'sandbox' ] ;
67
75
68
76
export function withLogging ( reducerFn ) {
69
77
if ( ! isLoggingEnabled ) {
@@ -79,7 +87,6 @@ export function withLogging(reducerFn) {
79
87
const newState = reducerFn ( prevState , action ) ;
80
88
81
89
const took = timer . now ( ) - started ;
82
- const diff = differ ( prevState , newState ) ;
83
90
84
91
const header = [
85
92
[
@@ -94,7 +101,7 @@ export function withLogging(reducerFn) {
94
101
] ;
95
102
96
103
if ( supportsGroups ) {
97
- console . group ( ...header ) ;
104
+ console . groupCollapsed ( ...header ) ;
98
105
} else {
99
106
console . log ( ...header ) ;
100
107
}
@@ -103,29 +110,38 @@ export function withLogging(reducerFn) {
103
110
console . log ( '%c action %O' , styles . action , action ) ;
104
111
console . log ( '%c new state %O' , styles . nextState , newState ) ;
105
112
106
- if ( ! diff ) {
107
- console . log (
108
- '%c diff %cno state change!' ,
109
- styles . prevState ,
110
- styles . error ,
111
- ) ;
113
+ if ( ! isDiffEnabled ) {
114
+ console . log ( '%c diff %c _disabled_' , styles . prevState , styles . note ) ;
112
115
} else {
113
- if ( supportsGroups ) {
114
- console . groupCollapsed ( ' diff' ) ;
115
- } else {
116
- console . log ( 'diff' ) ;
117
- }
116
+ const diff = differ (
117
+ omit ( diffIgnoreKeys , prevState ) ,
118
+ omit ( diffIgnoreKeys , newState ) ,
119
+ ) ;
118
120
119
- diff . forEach ( ( elem ) => {
121
+ if ( ! diff ) {
120
122
console . log (
121
- ` %c ${ styles . diff [ elem . kind ] . text } ` ,
122
- styles . diff [ elem . kind ] . style ,
123
- ... renderDiff ( elem ) ,
123
+ ' %c diff %cno state change!' ,
124
+ styles . prevState ,
125
+ styles . error ,
124
126
) ;
125
- } ) ;
126
-
127
- if ( supportsGroups ) {
128
- console . groupEnd ( ) ;
127
+ } else {
128
+ if ( supportsGroups ) {
129
+ console . groupCollapsed ( ' diff' ) ;
130
+ } else {
131
+ console . log ( 'diff' ) ;
132
+ }
133
+
134
+ diff . forEach ( ( elem ) => {
135
+ console . log (
136
+ `%c ${ styles . diff [ elem . kind ] . text } ` ,
137
+ styles . diff [ elem . kind ] . style ,
138
+ ...renderDiff ( elem ) ,
139
+ ) ;
140
+ } ) ;
141
+
142
+ if ( supportsGroups ) {
143
+ console . groupEnd ( ) ;
144
+ }
129
145
}
130
146
}
131
147
0 commit comments