MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / wrapReducer

Function wrapReducer

app/hooks/useJsonSearch.tsx:129–162  ·  view source on GitHub ↗
(
  name: string,
  reducer: React.Reducer<S, A>
)

Source from the content-addressed store, hash-verified

127let lastAction: any | undefined;
128
129function 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
164const getCurrentTimeFormatted = () => {
165 const currentTime = new Date();

Callers 1

JsonSearchProviderFunction · 0.85

Calls 2

reducerFunction · 0.85
getCurrentTimeFormattedFunction · 0.85

Tested by

no test coverage detected