为什么setIn不可以设置value为null或undefined?
Volankey opened this issue · comments
Volankey commented
const setIn = (segments: Segments, source: any, value: any) => {
for (let i = 0; i < segments.length; i++) {
const index = segments[i]
const rules = getDestructor(index as string)
if (!rules) {
if (!isValid(source)) return
if (!isValid(source[index])) {
// 有什么特殊意义吗?
if (!isValid(source[index]) && !isValid(value)) {
return
}
if (isNum(segments[i + 1])) {
source[index] = []
} else {
source[index] = {}
}
}
if (i === segments.length - 1) {
source[index] = value
}
source = source[index]
} else {
setInByDestructor(source, rules, value, { setIn, getIn })
break
}
}
}