* Store Injection
(
grabStoresFn: IStoresToProps,
component: IReactComponent<any>,
injectNames: string,
makeReactive: boolean
)
| 11 | * Store Injection |
| 12 | */ |
| 13 | function createStoreInjector( |
| 14 | grabStoresFn: IStoresToProps, |
| 15 | component: IReactComponent<any>, |
| 16 | injectNames: string, |
| 17 | makeReactive: boolean |
| 18 | ): IReactComponent<any> { |
| 19 | // Support forward refs |
| 20 | let Injector: IReactComponent<any> = React.forwardRef((props, ref) => { |
| 21 | const newProps = { ...props } |
| 22 | const context = React.useContext(MobXProviderContext) |
| 23 | Object.assign(newProps, grabStoresFn(context || {}, newProps) || {}) |
| 24 | |
| 25 | if (ref) { |
| 26 | newProps.ref = ref |
| 27 | } |
| 28 | |
| 29 | return React.createElement(component, newProps) |
| 30 | }) |
| 31 | |
| 32 | if (makeReactive) Injector = observer(Injector) |
| 33 | Injector["isMobxInjector"] = true // assigned late to suppress observer warning |
| 34 | |
| 35 | // Static fields from component should be visible on the generated Injector |
| 36 | copyStaticProperties(component, Injector) |
| 37 | Injector["wrappedComponent"] = component |
| 38 | Injector.displayName = getInjectName(component, injectNames) |
| 39 | return Injector |
| 40 | } |
| 41 | |
| 42 | function getInjectName(component: IReactComponent<any>, injectNames: string): string { |
| 43 | let displayName |
no test coverage detected
searching dependent graphs…