11( 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 ( ) ) ;
55} ( this , ( function ( ) { 'use strict' ;
66
77/**
@@ -34,26 +34,30 @@ function deepCopy (obj, cache) {
3434 }
3535
3636 // 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 ; } ) ;
3838 if ( hit ) {
3939 return hit . copy
4040 }
4141
42- var copy = Array . isArray ( obj ) ? [ ] : { }
42+ var copy = Array . isArray ( obj ) ? [ ] : { } ;
4343 // put the copy into cache at first
4444 // because we want to refer it in recursive deepCopy
4545 cache . push ( {
4646 original : obj ,
4747 copy : copy
48- } )
48+ } ) ;
4949
5050 Object . keys ( obj ) . forEach ( function ( key ) {
51- copy [ key ] = deepCopy ( obj [ key ] , cache )
52- } )
51+ copy [ key ] = deepCopy ( obj [ key ] , cache ) ;
52+ } ) ;
5353
5454 return copy
5555}
5656
57+ /**
58+ * forEach for object
59+ */
60+
5761// Credits: borrowed code from fcomb/redux-logger
5862
5963function createLogger ( ref ) {
@@ -63,40 +67,40 @@ function createLogger (ref) {
6367 var mutationTransformer = ref . mutationTransformer ; if ( mutationTransformer === void 0 ) mutationTransformer = function ( mut ) { return mut ; } ;
6468
6569 return function ( store ) {
66- var prevState = deepCopy ( store . state )
70+ var prevState = deepCopy ( store . state ) ;
6771
6872 store . subscribe ( function ( mutation , state ) {
6973 if ( typeof console === 'undefined' ) {
7074 return
7175 }
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 ;
7781 var startMessage = collapsed
7882 ? console . groupCollapsed
79- : console . group
83+ : console . group ;
8084
8185 // render
8286 try {
83- startMessage . call ( console , message )
87+ startMessage . call ( console , message ) ;
8488 } catch ( e ) {
85- console . log ( message )
89+ console . log ( message ) ;
8690 }
8791
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 ) ) ;
9195
9296 try {
93- console . groupEnd ( )
97+ console . groupEnd ( ) ;
9498 } catch ( e ) {
95- console . log ( 'ββ log end ββ' )
99+ console . log ( 'ββ log end ββ' ) ;
96100 }
97101
98- prevState = nextState
99- } )
102+ prevState = nextState ;
103+ } ) ;
100104 }
101105}
102106
@@ -110,4 +114,4 @@ function pad (num, maxLength) {
110114
111115return createLogger ;
112116
113- } ) ) ) ;
117+ } ) ) ) ;
0 commit comments