Skip to content

Commit 213706c

Browse files
committed
fix: connect do not update issue, close #202
1 parent f597b7e commit 213706c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

components/_util/proxyComponent.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function wrapWithConnect (WrappedComponent) {
99
const tempProps = WrappedComponent.props || {}
1010
const methods = WrappedComponent.methods || {}
1111
const props = {}
12-
Object.keys(tempProps).forEach(k => { props[k] = PropTypes.any })
12+
Object.keys(tempProps).forEach(k => { props[k] = ({ ...k, required: false }) })
1313
WrappedComponent.props.__propsSymbol__ = PropTypes.any
1414
WrappedComponent.props.children = PropTypes.array.def([])
1515
const ProxyWrappedComponent = {
@@ -22,19 +22,24 @@ export default function wrapWithConnect (WrappedComponent) {
2222
},
2323
},
2424
render () {
25-
const { $listeners, $slots = {}, $attrs } = this
25+
const { $listeners, $slots = {}, $attrs, $scopedSlots } = this
2626
const props = getOptionProps(this)
2727
const wrapProps = {
2828
props: {
2929
...props,
3030
__propsSymbol__: Symbol(),
31-
children: $slots.default || [],
31+
children: $slots.default || props.children || [],
3232
},
3333
on: $listeners,
3434
attrs: $attrs,
35+
scopedSlots: $scopedSlots,
3536
}
3637
return (
37-
<WrappedComponent {...wrapProps} ref='wrappedInstance'/>
38+
<WrappedComponent {...wrapProps} ref='wrappedInstance'>
39+
{Object.keys($slots).map(name => {
40+
return <template slot={name}>{$slots[name]}</template>
41+
})}
42+
</WrappedComponent>
3843
)
3944
},
4045
}

components/_util/store/connect.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import shallowEqual from 'shallowequal'
22
import omit from 'omit.js'
33
import { getOptionProps } from '../props-util'
44
import PropTypes from '../vue-types'
5+
import proxyComponent from '../proxyComponent'
56

67
function getDisplayName (WrappedComponent) {
78
return WrappedComponent.name || 'Component'
@@ -13,8 +14,10 @@ export default function connect (mapStateToProps) {
1314
const finnalMapStateToProps = mapStateToProps || defaultMapStateToProps
1415
return function wrapWithConnect (WrappedComponent) {
1516
const tempProps = omit(WrappedComponent.props || {}, ['store'])
16-
const props = {}
17-
Object.keys(tempProps).forEach(k => { props[k] = PropTypes.any })
17+
const props = {
18+
__propsSymbol__: PropTypes.any,
19+
}
20+
Object.keys(tempProps).forEach(k => { props[k] = ({ ...k, required: false }) })
1821
const Connect = {
1922
name: `Connect_${getDisplayName(WrappedComponent)}`,
2023
props,
@@ -28,7 +31,11 @@ export default function connect (mapStateToProps) {
2831
}
2932
},
3033
watch: {
31-
34+
__propsSymbol__ () {
35+
if (mapStateToProps && mapStateToProps.length === 2) {
36+
this.subscribed = finnalMapStateToProps(this.store.getState(), this.$props)
37+
}
38+
},
3239
},
3340
mounted () {
3441
this.trySubscribe()
@@ -88,6 +95,6 @@ export default function connect (mapStateToProps) {
8895
)
8996
},
9097
}
91-
return Connect
98+
return proxyComponent(Connect)
9299
}
93100
}

0 commit comments

Comments
 (0)