Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6370493

Browse files
committed
修复vue插槽变更时同步造成的假死状态,以及withRouter的优化
1 parent f8c4610 commit 6370493

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

src/applyReactInVue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default function applyReactInVue(component, options = {}) {
169169
// hack!!!! 一定要在render函数李触发,才能激活具名插槽
170170
slotsInit() {
171171
Object.keys(this.$slots).forEach((key) => {
172-
this.$slots[key]
172+
return this.$slots[key]
173173
})
174174
Object.keys(this.$scopedSlots).forEach((key) => {
175175
this.$scopedSlots[key]()

src/applyVueInReact.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ function getOptions (Component) {
3232
class GetReactRouterPropsCom extends React.Component {
3333
constructor (props) {
3434
super(props)
35-
let { history, match, location, forwardRef, ...newProps } = props
36-
this.state = {
37-
...newProps
38-
}
35+
let { history, match, location } = props
3936
// 设置react router属性绑定倒所有的vue的原型上
4037
setReactRouterInVue({
4138
history,
@@ -52,7 +49,8 @@ class GetReactRouterPropsCom extends React.Component {
5249
})
5350
}
5451
render () {
55-
return <VueComponentLoader {...this.state} ref={ this.props.forwardRef } />
52+
const { history, match, location, ...newProps } = this.props
53+
return <VueComponentLoader {...newProps} ref={ this.props.forwardRef } />
5654
}
5755
}
5856
const VueContainer = React.forwardRef((props, ref) => {
@@ -145,7 +143,6 @@ class VueComponentLoader extends React.Component {
145143
// 处理v-model
146144
doVModel (props) {
147145
let { $model, ...newProps } = props
148-
return {...newProps}
149146
if ($model === undefined) return props
150147
// 考虑到了自定义v-model
151148
let vueInstanceModelOption = { ...{ prop: 'value', event: 'input' }, ...getOptions(this.currentVueComponent).model }
@@ -280,14 +277,9 @@ class VueComponentLoader extends React.Component {
280277
this.getNamespaceSlots.__namespaceSlots[i] = newSlot
281278
} else {
282279
newSlot = this.getNamespaceSlots.__namespaceSlots[i]
283-
// 触发通信层更新fiberNode
284-
if (newSlot[0].child.reactInstance) {
280+
this.$nextTick(() => {
285281
newSlot[0].child.reactInstance.setState({ children: slot })
286-
} else {
287-
this.$nextTick(() => {
288-
newSlot[0].child.reactInstance.setState({ children: slot })
289-
})
290-
}
282+
})
291283
}
292284
newSlot.reactSlot = slot
293285
return newSlot
@@ -318,13 +310,9 @@ class VueComponentLoader extends React.Component {
318310
} else {
319311
newSlot = this.getScopedSlots.__scopeSlots[i]
320312
// 触发通信层更新fiberNode
321-
if (newSlot.child.reactInstance) {
313+
this.$nextTick(() => {
322314
newSlot.child.reactInstance.setState({ children: scopedSlot(context) })
323-
} else {
324-
this.$nextTick(() => {
325-
newSlot.child.reactInstance.setState({ children: scopedSlot(context) })
326-
})
327-
}
315+
})
328316
}
329317
return newSlot
330318
}
@@ -353,13 +341,9 @@ class VueComponentLoader extends React.Component {
353341
// Object.assign(this.getChildren.__vnode[0], createElement(applyReactInVue(() => children, {...options, isSlots: true})))
354342
newSlot = this.getChildren.__vnode
355343
// 直接修改react的fiberNode,此过程vnode无感知,此方案只是临时
356-
if (newSlot[0].child.reactInstance) {
344+
this.$nextTick(() => {
357345
newSlot[0].child.reactInstance.setState({ children })
358-
} else {
359-
this.$nextTick(() => {
360-
newSlot[0].child.reactInstance.setState({ children })
361-
})
362-
}
346+
})
363347
}
364348
newSlot.reactSlot = children
365349
return newSlot

0 commit comments

Comments
 (0)