Navigation Menu

Skip to content

Commit

Permalink
fix(taro-weapp): setData 前移出掉数据中的函数
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jul 31, 2018
1 parent 66de1ca commit cca3ed6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/taro-weapp/src/lifecycle.js
Expand Up @@ -3,6 +3,8 @@ import {
internal_safe_set as safeSet
} from '@tarojs/taro'
import { componentTrigger } from './create-component'
import { shakeFnFromObject, isEmptyObject } from './util'

const privatePropKeyName = '_triggerObserer'
export function updateComponent (component) {
const { props } = component
Expand Down Expand Up @@ -59,7 +61,17 @@ function doUpdate (component) {
const _data = {}
component.$usedState.forEach(key => {
const val = safeGet(data, key)
typeof val !== 'undefined' && safeSet(_data, key, val)
if (typeof val === 'undefined') {
return
}
if (typeof val === 'object') {
val = shakeFnFromObject(val)
if (!isEmptyObject(val)) {
safeSet(_data, key, val)
}
} else {
safeSet(_data, key, val)
}
})
data = _data
}
Expand Down
20 changes: 20 additions & 0 deletions packages/taro-weapp/src/util.js
Expand Up @@ -55,3 +55,23 @@ export function getPrototypeChain (obj) {
}

export function noop () {}

export function shakeFnFromObject (obj) {
let newObj = {}
if (typeof obj === 'object') {
for (const key in obj) {
if (typeof obj[key] === 'function') {
continue
}
if (typeof obj[key] === 'object') {
const ret = shakeFnFromObject(obj[key])
if (!isEmptyObject(ret)) {
newObj[key] = ret
}
} else {
newObj[key] = obj[key]
}
}
}
return newObj
}

0 comments on commit cca3ed6

Please sign in to comment.