(
stateFn: (state: HyperState) => stateProps,
dispatchFn: (dispatch: HyperDispatch) => dispatchProps,
c: any,
d: Options = {}
)
| 454 | // plugins can override mapToState, dispatchToProps |
| 455 | // and the class gets decorated (proxied) |
| 456 | export function connect<stateProps extends {}, dispatchProps>( |
| 457 | stateFn: (state: HyperState) => stateProps, |
| 458 | dispatchFn: (dispatch: HyperDispatch) => dispatchProps, |
| 459 | c: any, |
| 460 | d: Options = {} |
| 461 | ) { |
| 462 | return (Class: any, name: keyof typeof connectors) => { |
| 463 | return reduxConnect<stateProps, dispatchProps, any, HyperState>( |
| 464 | (state) => { |
| 465 | let ret = stateFn(state); |
| 466 | connectors[name].state.forEach((fn) => { |
| 467 | let ret_; |
| 468 | |
| 469 | try { |
| 470 | // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 471 | ret_ = fn(state, ret); |
| 472 | } catch (err) { |
| 473 | notify( |
| 474 | 'Plugin error', |
| 475 | `${fn._pluginName}: Error occurred in \`map${name}State\`. Check Developer Tools for details.`, |
| 476 | {error: err} |
| 477 | ); |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | if (!ret_ || typeof ret_ !== 'object') { |
| 482 | notify('Plugin error', `${fn._pluginName}: Invalid return value of \`map${name}State\` (object expected).`); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | ret = ret_; |
| 487 | }); |
| 488 | return ret; |
| 489 | }, |
| 490 | (dispatch) => { |
| 491 | let ret = dispatchFn(dispatch); |
| 492 | connectors[name].dispatch.forEach((fn) => { |
| 493 | let ret_; |
| 494 | |
| 495 | try { |
| 496 | // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 497 | ret_ = fn(dispatch, ret); |
| 498 | } catch (err) { |
| 499 | notify( |
| 500 | 'Plugin error', |
| 501 | `${fn._pluginName}: Error occurred in \`map${name}Dispatch\`. Check Developer Tools for details.`, |
| 502 | {error: err} |
| 503 | ); |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | if (!ret_ || typeof ret_ !== 'object') { |
| 508 | notify( |
| 509 | 'Plugin error', |
| 510 | `${fn._pluginName}: Invalid return value of \`map${name}Dispatch\` (object expected).` |
| 511 | ); |
| 512 | return; |
| 513 | } |
no test coverage detected