1
1
( function ( global , factory ) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( ) :
3
- typeof define === 'function' && define . amd ? define ( factory ) :
4
- ( global . createVuexLogger = factory ( ) ) ;
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( ) :
3
+ typeof define === 'function' && define . amd ? define ( factory ) :
4
+ ( global . createVuexLogger = factory ( ) ) ;
5
5
} ( this , ( function ( ) { 'use strict' ;
6
6
7
7
/**
@@ -34,26 +34,30 @@ function deepCopy (obj, cache) {
34
34
}
35
35
36
36
// if obj is hit, it is in circular structure
37
- var hit = find ( cache , function ( c ) { return c . original === obj ; } )
37
+ var hit = find ( cache , function ( c ) { return c . original === obj ; } ) ;
38
38
if ( hit ) {
39
39
return hit . copy
40
40
}
41
41
42
- var copy = Array . isArray ( obj ) ? [ ] : { }
42
+ var copy = Array . isArray ( obj ) ? [ ] : { } ;
43
43
// put the copy into cache at first
44
44
// because we want to refer it in recursive deepCopy
45
45
cache . push ( {
46
46
original : obj ,
47
47
copy : copy
48
- } )
48
+ } ) ;
49
49
50
50
Object . keys ( obj ) . forEach ( function ( key ) {
51
- copy [ key ] = deepCopy ( obj [ key ] , cache )
52
- } )
51
+ copy [ key ] = deepCopy ( obj [ key ] , cache ) ;
52
+ } ) ;
53
53
54
54
return copy
55
55
}
56
56
57
+ /**
58
+ * forEach for object
59
+ */
60
+
57
61
// Credits: borrowed code from fcomb/redux-logger
58
62
59
63
function createLogger ( ref ) {
@@ -63,40 +67,40 @@ function createLogger (ref) {
63
67
var mutationTransformer = ref . mutationTransformer ; if ( mutationTransformer === void 0 ) mutationTransformer = function ( mut ) { return mut ; } ;
64
68
65
69
return function ( store ) {
66
- var prevState = deepCopy ( store . state )
70
+ var prevState = deepCopy ( store . state ) ;
67
71
68
72
store . subscribe ( function ( mutation , state ) {
69
73
if ( typeof console === 'undefined' ) {
70
74
return
71
75
}
72
- var nextState = deepCopy ( state )
73
- var time = new Date ( )
74
- var formattedTime = " @ " + ( pad ( time . getHours ( ) , 2 ) ) + ":" + ( pad ( time . getMinutes ( ) , 2 ) ) + ":" + ( pad ( time . getSeconds ( ) , 2 ) ) + "." + ( pad ( time . getMilliseconds ( ) , 3 ) )
75
- var formattedMutation = mutationTransformer ( mutation )
76
- var message = "mutation " + ( mutation . type ) + formattedTime
76
+ 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 ;
77
81
var startMessage = collapsed
78
82
? console . groupCollapsed
79
- : console . group
83
+ : console . group ;
80
84
81
85
// render
82
86
try {
83
- startMessage . call ( console , message )
87
+ startMessage . call ( console , message ) ;
84
88
} catch ( e ) {
85
- console . log ( message )
89
+ console . log ( message ) ;
86
90
}
87
91
88
- console . log ( '%c prev state' , 'color: #9E9E9E; font-weight: bold' , transformer ( prevState ) )
89
- console . log ( '%c mutation' , 'color: #03A9F4; font-weight: bold' , formattedMutation )
90
- console . log ( '%c next state' , 'color: #4CAF50; font-weight: bold' , transformer ( nextState ) )
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 ) ) ;
91
95
92
96
try {
93
- console . groupEnd ( )
97
+ console . groupEnd ( ) ;
94
98
} catch ( e ) {
95
- console . log ( 'ββ log end ββ' )
99
+ console . log ( 'ββ log end ββ' ) ;
96
100
}
97
101
98
- prevState = nextState
99
- } )
102
+ prevState = nextState ;
103
+ } ) ;
100
104
}
101
105
}
102
106
@@ -110,4 +114,4 @@ function pad (num, maxLength) {
110
114
111
115
return createLogger ;
112
116
113
- } ) ) ) ;
117
+ } ) ) ) ;
0 commit comments