Skip to content

Commit 259253a

Browse files
committed
Rework connect tests, combine warnings, and remove observedBits
Ported connect test handling from 995 Deduped the "custom store context" messages Removed use of observedBits for now Commented out derivedProps propTypes that caused test failures
1 parent 106a7e1 commit 259253a

File tree

2 files changed

+175
-107
lines changed

2 files changed

+175
-107
lines changed

src/components/connectAdvanced.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ export default function connectAdvanced(
3535
// probably overridden by wrapper functions such as connect()
3636
methodName = 'connectAdvanced',
3737

38-
// if defined, the name of the property passed to the wrapped element indicating the number of
38+
// REMOVED: if defined, the name of the property passed to the wrapped element indicating the number of
3939
// calls to render. useful for watching in react devtools for unnecessary re-renders.
4040
renderCountProp = undefined,
4141

4242
// determines whether this HOC subscribes to store changes
4343
shouldHandleStateChanges = true,
4444

45-
// the key of props/context to get the store [**does nothing, use consumer**]
45+
// REMOVED: the key of props/context to get the store
4646
storeKey = 'store',
4747

4848
// REMOVED: expose the wrapped component via refs
@@ -66,11 +66,13 @@ export default function connectAdvanced(
6666
"withRef is removed. To access the wrapped instance, use a ref on the connected component"
6767
)
6868

69+
const customStoreWarningMessage = 'To use a custom Redux store for specific components, create a custom React context with ' +
70+
'React.createContext(), and pass the context object to React-Redux\'s Provider and specific components' +
71+
' like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. ' +
72+
'You may also pass a {context : MyContext} option to connect'
73+
6974
invariant(storeKey === 'store',
70-
'storeKey has been removed and does not do anything. To use a custom redux store for a single component, ' +
71-
'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' +
72-
'and the Consumer to this component as in <Provider context={context.Provider}><' +
73-
'ConnectedComponent consumer={context.Consumer} /></Provider>'
75+
'storeKey has been removed and does not do anything. ' + customStoreWarningMessage
7476
)
7577

7678

@@ -103,7 +105,7 @@ export default function connectAdvanced(
103105
}
104106
}
105107
PureWrapperRef.propTypes = {
106-
derivedProps: propTypes.object,
108+
//derivedProps: propTypes.object,
107109
forwardRef: propTypes.oneOfType([
108110
propTypes.func,
109111
propTypes.object
@@ -121,7 +123,7 @@ export default function connectAdvanced(
121123
}
122124
}
123125
PureWrapperNoRef.propTypes = {
124-
derivedProps: propTypes.object,
126+
//derivedProps: propTypes.object,
125127
}
126128
PureWrapper = PureWrapperNoRef
127129
}
@@ -144,11 +146,7 @@ export default function connectAdvanced(
144146
constructor(props) {
145147
super(props)
146148
invariant(forwardRef ? !props.props[storeKey] : !props[storeKey],
147-
'Passing redux store in props has been removed and does not do anything. ' +
148-
'To use a custom redux store for a single component, ' +
149-
'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' +
150-
'and the Consumer to this component\'s connect as in <Provider context={context.Provider}></Provider>' +
151-
` and connect(mapState, mapDispatch, undefined, { consumer=context.consumer })(${wrappedComponentName})`
149+
'Passing redux store in props has been removed and does not do anything. ' + customStoreWarningMessage
152150
)
153151
this.generatedDerivedProps = this.makeDerivedPropsGenerator()
154152
this.renderWrappedComponent = this.renderWrappedComponent.bind(this)
@@ -213,13 +211,6 @@ export default function connectAdvanced(
213211
}
214212

215213
render() {
216-
if (this.props.unstable_observedBits) {
217-
return (
218-
<Context.Consumer unstable_observedBits={this.props.unstable_observedBits}>
219-
{this.renderWrappedComponent}
220-
</Context.Consumer>
221-
)
222-
}
223214
return (
224215
<Context.Consumer>
225216
{this.renderWrappedComponent}

0 commit comments

Comments
 (0)