Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2844 from korhaliv/chore/patch-redux-connect
Browse files Browse the repository at this point in the history
chore: allow overriding state props in sb components
  • Loading branch information
mrfelton authored Sep 3, 2019
2 parents 242b2bd + f4e0941 commit bdeac07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
33 changes: 33 additions & 0 deletions .storybook/patchedReactRedux.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export {
Provider,
connectAdvanced,
ReactReduxContext,
batch,
useDispatch,
useSelector,
useStore,
shallowEqual,
} from '../node_modules/react-redux' // full import path to avoid circular dep
import { connect as originalConnect } from '../node_modules/react-redux'

function defaultMergeProps(stateProps, dispatchProps, ownProps) {
return { ...stateProps, ...dispatchProps, ...ownProps }
}

/**
* connect - Patches redux connect function to use `defaultMergeProps` that prioritizes `ownProps` over `stateProps`.
*
* @param {*} mapStateToProps mapStateToProps
* @param {*} mapDispatchToProps mapDispatchToProps
* @param {*} [mergeProps=defaultMergeProps] mergeProps
* @param {*} rest options
* @returns {*}
*/
export function connect(
mapStateToProps,
mapDispatchToProps,
mergeProps = defaultMergeProps,
...rest
) {
return originalConnect(mapStateToProps, mapDispatchToProps, mergeProps, ...rest)
}
16 changes: 12 additions & 4 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
require('@babel/register')
const baseConfig = require('../webpack/webpack.config.base')
const path = require('path')

module.exports = ({ config }) => ({
...config,
resolve: {
const createResolveConfig = config => {
const resolveConfig = {
...config.resolve,
...baseConfig.default.resolve,
},
}
resolveConfig.alias['react-redux'] = path.resolve(__dirname, './patchedReactRedux')
return resolveConfig
}

module.exports = ({ config }) => ({
...config,
resolve: createResolveConfig(config),

module: {
...config.module,
rules: [
Expand Down

0 comments on commit bdeac07

Please sign in to comment.