Skip to content

Commit

Permalink
fix(taro-weapp/swan/tt/qq/): 修复 props 系统问题
Browse files Browse the repository at this point in the history
1. observer 中 updateComponent 的调用改为异步
2. compid 存在时才监听此 component
  • Loading branch information
Chen-jj committed Apr 29, 2019
1 parent a6af8f5 commit a4ed9e8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
8 changes: 5 additions & 3 deletions packages/taro-qq/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ function initComponent (ComponentClass, isPage) {
// 动态组件执行改造函数副本的时,在初始化数据前计算好props
if (!isPage) {
const compid = this.data.compid
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
if (compid) {
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
}
}
const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props)
this.$component.props = nextProps
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-qq/src/propsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateComponent } from './lifecycle'
import { filterProps } from './create-component'
import nextTick from './next-tick'

class Manager {
map = {}
Expand All @@ -25,7 +26,7 @@ class Manager {
const nextProps = filterProps(ComponentClass.defaultProps, props, component.props)
component.props = nextProps
component._unsafeCallUpdate = true
updateComponent(component)
nextTick(() => updateComponent(component))
component._unsafeCallUpdate = false
}
})
Expand Down
8 changes: 5 additions & 3 deletions packages/taro-swan/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ function initComponent (ComponentClass, isPage) {
// 动态组件执行改造函数副本的时,在初始化数据前计算好props
if (hasPageInited && !isPage) {
const compid = this.data.compid
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
if (compid) {
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
}
}
const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props)
this.$component.props = nextProps
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-swan/src/propsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateComponent } from './lifecycle'
import { filterProps } from './create-component'
import nextTick from './next-tick'

class Manager {
map = {}
Expand All @@ -25,7 +26,7 @@ class Manager {
const nextProps = filterProps(ComponentClass.defaultProps, props, component.props)
component.props = nextProps
component._unsafeCallUpdate = true
updateComponent(component)
nextTick(() => updateComponent(component))
component._unsafeCallUpdate = false
}
})
Expand Down
8 changes: 5 additions & 3 deletions packages/taro-tt/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ function initComponent (ComponentClass, isPage) {
// 动态组件执行改造函数副本的时,在初始化数据前计算好props
if (hasPageInited && !isPage) {
const compid = this.data.compid
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
if (compid) {
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
}
}
const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props)
this.$component.props = nextProps
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-tt/src/propsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateComponent } from './lifecycle'
import { filterProps } from './create-component'
import nextTick from './next-tick'

class Manager {
map = {}
Expand All @@ -25,7 +26,7 @@ class Manager {
const nextProps = filterProps(ComponentClass.defaultProps, props, component.props)
component.props = nextProps
component._unsafeCallUpdate = true
updateComponent(component)
nextTick(() => updateComponent(component))
component._unsafeCallUpdate = false
}
})
Expand Down
8 changes: 5 additions & 3 deletions packages/taro-weapp/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ function initComponent (ComponentClass, isPage) {
// 动态组件执行改造函数副本的时,在初始化数据前计算好props
if (!isPage) {
const compid = this.data.compid
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
if (compid) {
propsManager.observers[compid] = {
component: this.$component,
ComponentClass
}
}
const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props)
this.$component.props = nextProps
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-weapp/src/propsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateComponent } from './lifecycle'
import { filterProps } from './create-component'
import nextTick from './next-tick'

class Manager {
map = {}
Expand All @@ -25,7 +26,7 @@ class Manager {
const nextProps = filterProps(ComponentClass.defaultProps, props, component.props)
component.props = nextProps
component._unsafeCallUpdate = true
updateComponent(component)
nextTick(() => updateComponent(component))
component._unsafeCallUpdate = false
}
})
Expand Down

0 comments on commit a4ed9e8

Please sign in to comment.