@@ -13,9 +13,9 @@ import diffLogger from './diff';
1313 */
1414function getLogLevel ( level , action , payload , type ) {
1515 switch ( typeof level ) {
16- case ` object` :
17- return typeof level [ type ] === ` function` ? level [ type ] ( ...payload ) : level [ type ] ;
18- case ` function` :
16+ case ' object' :
17+ return typeof level [ type ] === ' function' ? level [ type ] ( ...payload ) : level [ type ] ;
18+ case ' function' :
1919 return level ( action ) ;
2020 default :
2121 return level ;
@@ -29,17 +29,17 @@ function defaultTitleFormatter(options) {
2929 } = options ;
3030
3131 return ( action , time , took ) => {
32- const parts = [ ` action` ] ;
32+ const parts = [ ' action' ] ;
3333
3434 parts . push ( `%c${ String ( action . type ) } ` ) ;
3535 if ( timestamp ) parts . push ( `%c@ ${ time } ` ) ;
3636 if ( duration ) parts . push ( `%c(in ${ took . toFixed ( 2 ) } ms)` ) ;
3737
38- return parts . join ( ` ` ) ;
38+ return parts . join ( ' ' ) ;
3939 } ;
4040}
4141
42- export function printBuffer ( buffer , options ) {
42+ function printBuffer ( buffer , options ) {
4343 const {
4444 logger,
4545 actionTransformer,
@@ -50,7 +50,7 @@ export function printBuffer(buffer, options) {
5050 diff,
5151 } = options ;
5252
53- const isUsingDefaultFormatter = typeof options . titleFormatter === ` undefined` ;
53+ const isUsingDefaultFormatter = typeof options . titleFormatter === ' undefined' ;
5454
5555 buffer . forEach ( ( logEntry , key ) => {
5656 const { started, startedTime, action, prevState, error } = logEntry ;
@@ -64,52 +64,53 @@ export function printBuffer(buffer, options) {
6464
6565 // Message
6666 const formattedAction = actionTransformer ( action ) ;
67- const isCollapsed = ( typeof collapsed === ` function` ) ? collapsed ( ( ) => nextState , action , logEntry ) : collapsed ;
67+ const isCollapsed = ( typeof collapsed === ' function' ) ? collapsed ( ( ) => nextState , action , logEntry ) : collapsed ;
6868
6969 const formattedTime = formatTime ( startedTime ) ;
70- const titleCSS = colors . title ? `color: ${ colors . title ( formattedAction ) } ;` : `` ;
71- const headerCSS = [ ` color: gray; font-weight: lighter;` ] ;
70+ const titleCSS = colors . title ? `color: ${ colors . title ( formattedAction ) } ;` : '' ;
71+ const headerCSS = [ ' color: gray; font-weight: lighter;' ] ;
7272 headerCSS . push ( titleCSS ) ;
73- if ( options . timestamp ) headerCSS . push ( ` color: gray; font-weight: lighter;` ) ;
74- if ( options . duration ) headerCSS . push ( ` color: gray; font-weight: lighter;` ) ;
73+ if ( options . timestamp ) headerCSS . push ( ' color: gray; font-weight: lighter;' ) ;
74+ if ( options . duration ) headerCSS . push ( ' color: gray; font-weight: lighter;' ) ;
7575 const title = titleFormatter ( formattedAction , formattedTime , took ) ;
7676
7777 // Render
7878 try {
7979 if ( isCollapsed ) {
8080 if ( colors . title && isUsingDefaultFormatter ) logger . groupCollapsed ( `%c ${ title } ` , ...headerCSS ) ;
8181 else logger . groupCollapsed ( title ) ;
82+ } else if ( colors . title && isUsingDefaultFormatter ) {
83+ logger . group ( `%c ${ title } ` , ...headerCSS ) ;
8284 } else {
83- if ( colors . title && isUsingDefaultFormatter ) logger . group ( `%c ${ title } ` , ...headerCSS ) ;
84- else logger . group ( title ) ;
85+ logger . group ( title ) ;
8586 }
8687 } catch ( e ) {
8788 logger . log ( title ) ;
8889 }
8990
90- const prevStateLevel = getLogLevel ( level , formattedAction , [ prevState ] , ` prevState` ) ;
91- const actionLevel = getLogLevel ( level , formattedAction , [ formattedAction ] , ` action` ) ;
92- const errorLevel = getLogLevel ( level , formattedAction , [ error , prevState ] , ` error` ) ;
93- const nextStateLevel = getLogLevel ( level , formattedAction , [ nextState ] , ` nextState` ) ;
91+ const prevStateLevel = getLogLevel ( level , formattedAction , [ prevState ] , ' prevState' ) ;
92+ const actionLevel = getLogLevel ( level , formattedAction , [ formattedAction ] , ' action' ) ;
93+ const errorLevel = getLogLevel ( level , formattedAction , [ error , prevState ] , ' error' ) ;
94+ const nextStateLevel = getLogLevel ( level , formattedAction , [ nextState ] , ' nextState' ) ;
9495
9596 if ( prevStateLevel ) {
96- if ( colors . prevState ) logger [ prevStateLevel ] ( ` %c prev state` , `color: ${ colors . prevState ( prevState ) } ; font-weight: bold` , prevState ) ;
97- else logger [ prevStateLevel ] ( ` prev state` , prevState ) ;
97+ if ( colors . prevState ) logger [ prevStateLevel ] ( ' %c prev state' , `color: ${ colors . prevState ( prevState ) } ; font-weight: bold` , prevState ) ;
98+ else logger [ prevStateLevel ] ( ' prev state' , prevState ) ;
9899 }
99100
100101 if ( actionLevel ) {
101- if ( colors . action ) logger [ actionLevel ] ( ` %c action ` , `color: ${ colors . action ( formattedAction ) } ; font-weight: bold` , formattedAction ) ;
102- else logger [ actionLevel ] ( ` action ` , formattedAction ) ;
102+ if ( colors . action ) logger [ actionLevel ] ( ' %c action ' , `color: ${ colors . action ( formattedAction ) } ; font-weight: bold` , formattedAction ) ;
103+ else logger [ actionLevel ] ( ' action ' , formattedAction ) ;
103104 }
104105
105106 if ( error && errorLevel ) {
106- if ( colors . error ) logger [ errorLevel ] ( ` %c error ` , `color: ${ colors . error ( error , prevState ) } ; font-weight: bold;` , error ) ;
107- else logger [ errorLevel ] ( ` error ` , error ) ;
107+ if ( colors . error ) logger [ errorLevel ] ( ' %c error ' , `color: ${ colors . error ( error , prevState ) } ; font-weight: bold;` , error ) ;
108+ else logger [ errorLevel ] ( ' error ' , error ) ;
108109 }
109110
110111 if ( nextStateLevel ) {
111- if ( colors . nextState ) logger [ nextStateLevel ] ( ` %c next state` , `color: ${ colors . nextState ( nextState ) } ; font-weight: bold` , nextState ) ;
112- else logger [ nextStateLevel ] ( ` next state` , nextState ) ;
112+ if ( colors . nextState ) logger [ nextStateLevel ] ( ' %c next state' , `color: ${ colors . nextState ( nextState ) } ; font-weight: bold` , nextState ) ;
113+ else logger [ nextStateLevel ] ( ' next state' , nextState ) ;
113114 }
114115
115116 if ( diff ) {
@@ -119,7 +120,9 @@ export function printBuffer(buffer, options) {
119120 try {
120121 logger . groupEnd ( ) ;
121122 } catch ( e ) {
122- logger . log ( ` —— log end ——` ) ;
123+ logger . log ( ' —— log end ——' ) ;
123124 }
124125 } ) ;
125126}
127+
128+ export default printBuffer ;
0 commit comments