MCPcopy Create free account
hub / github.com/byte-fe/react-model / connect

Function connect

src/index.tsx:406–438  ·  view source on GitHub ↗
(
  modelName: string,
  mapState?: Function | undefined,
  mapActions?: Function | undefined
)

Source from the content-addressed store, hash-verified

404}
405
406const connect = (
407 modelName: string,
408 mapState?: Function | undefined,
409 mapActions?: Function | undefined
410) => (Component: typeof React.Component | typeof PureComponent) =>
411 class P extends PureComponent<any> {
412 render() {
413 const { state: prevState = {}, actions: prevActions = {} } = this.props
414 return (
415 <Consumer>
416 {(models) => {
417 const { [`${modelName}`]: state } = models as any
418 const actions = Global.Actions[modelName]
419 return (
420 <Component
421 {...this.props}
422 state={{
423 ...prevState,
424 ...(mapState ? mapState(state) : state)
425 }}
426 actions={{
427 ...prevActions,
428 ...(mapActions
429 ? mapActions(consumerActions(actions, { modelName }))
430 : consumerActions(actions, { modelName }))
431 }}
432 />
433 )
434 }}
435 </Consumer>
436 )
437 }
438 }
439
440export {
441 actionMiddlewares,

Callers 5

connect.spec.tsxFile · 0.90
class.spec.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…