提交 01eb0d07 编写于 作者: D dolymood

fix(create-api): do not cancel watchers on create

上级 b47316d7
...@@ -84,8 +84,6 @@ export default function createAPIComponent(Vue, Component, events = [], single = ...@@ -84,8 +84,6 @@ export default function createAPIComponent(Vue, Component, events = [], single =
renderFn = null renderFn = null
} }
cancelWatchProps()
// to get Vue options // to get Vue options
// store router i18n ... // store router i18n ...
const options = { const options = {
...@@ -106,19 +104,21 @@ export default function createAPIComponent(Vue, Component, events = [], single = ...@@ -106,19 +104,21 @@ export default function createAPIComponent(Vue, Component, events = [], single =
const eventBeforeDestroy = 'hook:beforeDestroy' const eventBeforeDestroy = 'hook:beforeDestroy'
const component = api.open(renderData, renderFn, options) let component = api.open(renderData, renderFn, options)
let oldOwnerInstance = component.__cube__parent let oldOwnerInstance = component.__cube__parent
if (oldOwnerInstance !== ownerInstance) { if (oldOwnerInstance !== ownerInstance) {
if (oldOwnerInstance) { if (oldOwnerInstance) {
cancelWatchProps(oldOwnerInstance)
oldOwnerInstance.$off(eventBeforeDestroy, oldOwnerInstance.__cube_destroy_handler) oldOwnerInstance.$off(eventBeforeDestroy, oldOwnerInstance.__cube_destroy_handler)
oldOwnerInstance.__cube_destroy_handler = null oldOwnerInstance.__cube_destroy_handler = null
} }
oldOwnerInstance = component.__cube__parent = ownerInstance oldOwnerInstance = component.__cube__parent = ownerInstance
const beforeDestroy = function () { const beforeDestroy = function () {
cancelWatchProps() cancelWatchProps(ownerInstance)
if (oldOwnerInstance === ownerInstance) { if (oldOwnerInstance === ownerInstance) {
component.remove() component.remove()
oldOwnerInstance = component.__cube__parent = null oldOwnerInstance = component.__cube__parent = null
component = null
} }
ownerInstance.$off(eventBeforeDestroy, beforeDestroy) ownerInstance.$off(eventBeforeDestroy, beforeDestroy)
} }
...@@ -148,17 +148,16 @@ export default function createAPIComponent(Vue, Component, events = [], single = ...@@ -148,17 +148,16 @@ export default function createAPIComponent(Vue, Component, events = [], single =
} }
}) })
if (isInVueInstance) { if (isInVueInstance) {
ownerInstance.__createAPI_watchers.push( const cancelWatcher = ownerInstance.$watch(function () {
ownerInstance.$watch(function () { const props = {}
const props = {} watchKeys.forEach((key, i) => {
watchKeys.forEach((key, i) => { props[key] = ownerInstance[watchPropKeys[i]]
props[key] = ownerInstance[watchPropKeys[i]]
})
return props
}, function (newProps) {
component && component.$updateProps(newProps)
}) })
) return props
}, function (newProps) {
component && component.$updateProps(newProps)
})
ownerInstance.__createAPI_watchers.push(cancelWatcher)
} }
} }
} }
...@@ -188,7 +187,7 @@ export default function createAPIComponent(Vue, Component, events = [], single = ...@@ -188,7 +187,7 @@ export default function createAPIComponent(Vue, Component, events = [], single =
}) })
} }
function cancelWatchProps() { function cancelWatchProps(ownerInstance) {
if (ownerInstance.__createAPI_watchers) { if (ownerInstance.__createAPI_watchers) {
ownerInstance.__createAPI_watchers.forEach((watcher) => { ownerInstance.__createAPI_watchers.forEach((watcher) => {
watcher() watcher()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册