MCPcopy Index your code
hub / github.com/vercel/hyper / decorateReducer

Function decorateReducer

lib/utils/plugins.ts:529–558  ·  view source on GitHub ↗
(name: T, fn: any)

Source from the content-addressed store, hash-verified

527 (name: 'reduceSessions', fn: ISessionReducer): ISessionReducer;
528 (name: 'reduceTermGroups', fn: ITermGroupReducer): ITermGroupReducer;
529} = <T extends keyof typeof reducersDecorators>(name: T, fn: any) => {
530 const reducers = reducersDecorators[name];
531 return (state: any, action: any) => {
532 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
533 let state_ = fn(state, action);
534
535 reducers.forEach((pluginReducer: any) => {
536 let state__;
537
538 try {
539 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
540 state__ = pluginReducer(state_, action);
541 } catch (err) {
542 notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
543 error: err
544 });
545 return;
546 }
547
548 if (!state__ || typeof state__ !== 'object') {
549 notify('Plugin error', `${fn._pluginName}: Invalid return value of \`${name}\`.`);
550 return;
551 }
552
553 state_ = state__;
554 });
555
556 return state_;
557 };
558};
559
560export function decorateTermGroupsReducer(fn: ITermGroupReducer) {
561 return decorateReducer('reduceTermGroups', fn);

Callers 3

decorateUIReducerFunction · 0.85
decorateSessionsReducerFunction · 0.85

Calls 3

fnFunction · 0.85
notifyFunction · 0.70
forEachMethod · 0.45

Tested by

no test coverage detected