88
99import PropTypes from 'prop-types' ;
1010import React , { type ComponentType } from 'react' ;
11- import { ReactReduxContext } from 'react-redux' ;
11+ import ReactRedux from 'react-redux' ;
1212import type { Reducer } from 'redux' ;
1313import { createRPCHandler , createRPCReactors } from 'fusion-rpc-redux' ;
1414
@@ -57,8 +57,28 @@ export function withRPCRedux<Props: {}>(
5757 return ( Component : ComponentType < Props > ) => {
5858 const withRPCRedux = ( oldProps , context ) => {
5959 const { rpc} = context ;
60- return (
61- < ReactReduxContext . Consumer >
60+ return context . store && ! ReactRedux . ReactReduxContext ? (
61+ ( function ( ) {
62+ if ( mapStateToParams ) {
63+ const mapState = mapStateToParams ;
64+ mapStateToParams = ( state , args ) => mapState ( state , args , oldProps ) ;
65+ }
66+ const handler = createRPCHandler ( {
67+ rpcId,
68+ rpc,
69+ store : context . store ,
70+ actions,
71+ mapStateToParams,
72+ transformParams,
73+ } ) ;
74+ const props = {
75+ ...oldProps ,
76+ [ propName ] : handler ,
77+ } ;
78+ return React . createElement ( Component , props ) ;
79+ } ) ( )
80+ ) : (
81+ < ReactRedux . ReactReduxContext . Consumer >
6282 { ( { store} ) => {
6383 if ( mapStateToParams ) {
6484 const mapState = mapStateToParams ;
@@ -79,13 +99,14 @@ export function withRPCRedux<Props: {}>(
7999 } ;
80100 return React . createElement ( Component , props ) ;
81101 } }
82- </ ReactReduxContext . Consumer >
102+ </ ReactRedux . ReactReduxContext . Consumer >
83103 ) ;
84104 } ;
85105 const displayName = Component . displayName || Component . name || 'Anonymous' ;
86106 withRPCRedux . displayName = 'WithRPCRedux' + '(' + displayName + ')' ;
87107 withRPCRedux . contextTypes = {
88108 rpc : PropTypes . object . isRequired ,
109+ store : PropTypes . object ,
89110 } ;
90111 return withRPCRedux ;
91112 } ;
0 commit comments