( name: string, reducer: React.Reducer<S, A> )
| 127 | let lastAction: any | undefined; |
| 128 | |
| 129 | function wrapReducer<S, A extends { type: string }>( |
| 130 | name: string, |
| 131 | reducer: React.Reducer<S, A> |
| 132 | ): React.Reducer<S, A> { |
| 133 | return (state, action) => { |
| 134 | const next = reducer(state, action); |
| 135 | |
| 136 | if (process.env.NODE_ENV !== "production") { |
| 137 | if (!lastAction) { |
| 138 | console.groupCollapsed( |
| 139 | `%cAction: %c${ |
| 140 | name + " " + action.type |
| 141 | } %cat ${getCurrentTimeFormatted()}`, |
| 142 | "color: lightgreen; font-weight: bold;", |
| 143 | "color: white; font-weight: bold;", |
| 144 | "color: lightblue; font-weight: lighter;" |
| 145 | ); |
| 146 | console.log( |
| 147 | "%cPrevious State:", |
| 148 | "color: #9E9E9E; font-weight: 700;", |
| 149 | state |
| 150 | ); |
| 151 | console.log("%cAction:", "color: #00A7F7; font-weight: 700;", action); |
| 152 | console.log("%cNext State:", "color: #47B04B; font-weight: 700;", next); |
| 153 | console.groupEnd(); |
| 154 | lastAction = action; |
| 155 | } else { |
| 156 | lastAction = undefined; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return next; |
| 161 | }; |
| 162 | } |
| 163 | |
| 164 | const getCurrentTimeFormatted = () => { |
| 165 | const currentTime = new Date(); |
no test coverage detected