From 158e8d32d525c5b4f657620cbd8bac025c31741b Mon Sep 17 00:00:00 2001 From: A2ZH Date: Thu, 31 May 2018 15:50:09 -0500 Subject: [PATCH] Remove subkey (#945) * Add test for custom store key to connect * Remove subkey --- src/components/Provider.js | 4 ++-- src/connect/selectorFactory.js | 4 ++-- test/components/connect.spec.js | 24 +++++++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/Provider.js b/src/components/Provider.js index 71409a79a..f78e25e65 100644 --- a/src/components/Provider.js +++ b/src/components/Provider.js @@ -19,8 +19,8 @@ function warnAboutReceivingStore() { ) } -export function createProvider(storeKey = 'store', subKey) { - const subscriptionKey = subKey || `${storeKey}Subscription` +export function createProvider(storeKey = 'store') { + const subscriptionKey = `${storeKey}Subscription` class Provider extends Component { getChildContext() { diff --git a/src/connect/selectorFactory.js b/src/connect/selectorFactory.js index 4479431e0..de34b3361 100644 --- a/src/connect/selectorFactory.js +++ b/src/connect/selectorFactory.js @@ -1,5 +1,5 @@ import verifySubselectors from './verifySubselectors' - + export function impureFinalPropsSelectorFactory( mapStateToProps, mapDispatchToProps, @@ -64,7 +64,7 @@ export function pureFinalPropsSelectorFactory( const nextStateProps = mapStateToProps(state, ownProps) const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps) stateProps = nextStateProps - + if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps) diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 2d3e975ce..06951c17f 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -6,7 +6,7 @@ import PropTypes from 'prop-types' import ReactDOM from 'react-dom' import TestRenderer from 'react-test-renderer' import { createStore } from 'redux' -import { connect } from '../../src/index' +import { connect, createProvider } from '../../src/index' describe('React', () => { describe('connect', () => { @@ -2324,5 +2324,27 @@ describe('React', () => { expect(mapStateToPropsC).toHaveBeenCalledTimes(2) expect(mapStateToPropsD).toHaveBeenCalledTimes(2) }) + + it('should receive the store in the context using a custom store key', () => { + const store = createStore(() => ({})) + const CustomProvider = createProvider('customStoreKey') + const connectOptions = { storeKey: 'customStoreKey' } + + @connect(undefined, undefined, undefined, connectOptions) + class Container extends Component { + render() { + return + } + } + + const testRenderer = TestRenderer.create( + + + + ) + + const container = testRenderer.root.findByType(Container) + expect(container.instance.store).toBe(store) + }) }) })