dao42/wechat-weapp-mobx

能解释下 这个方法干什么的吗?

Closed this issue · 1 comments

function syncKeys(current, pre) { if (current === pre) return const rootCurrentType = type(current) const rootPreType = type(pre) if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) { if(Object.keys(current).length >= Object.keys(pre).length){ for (let key in pre) { const currentValue = current[key] if (currentValue === undefined) { current[key] = null } else { syncKeys(currentValue, pre[key]) } } } } else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) { if (current.length >= pre.length) { pre.forEach((item, index) => { syncKeys(current[index], item) }) } } }

windy commented

做 diff 之前的 key 同步,提升 setData 的性能。有啥问题吗?