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

chore: allow overriding state props in sb components #2844

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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