Skip to content

Commit

Permalink
Remove subkey (reduxjs#945)
Browse files Browse the repository at this point in the history
* Add test for custom store key to connect

* Remove subkey
  • Loading branch information
theJian authored and josepot committed Sep 21, 2018
1 parent 1b99f2e commit 158e8d3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/connect/selectorFactory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import verifySubselectors from './verifySubselectors'

export function impureFinalPropsSelectorFactory(
mapStateToProps,
mapDispatchToProps,
Expand Down Expand Up @@ -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)

Expand Down
24 changes: 23 additions & 1 deletion test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 <Passthrough {...this.props} />
}
}

const testRenderer = TestRenderer.create(
<CustomProvider store={store}>
<Container />
</CustomProvider>
)

const container = testRenderer.root.findByType(Container)
expect(container.instance.store).toBe(store)
})
})
})

0 comments on commit 158e8d3

Please sign in to comment.