In triggerEffects, it is not necessary to determine whether the dep parameter is an Array
What problem does this feature solve?
在 triggerEffects
函数中,对 dep
的判断多余,将 dep:Set
展开到一个数组的操作多余。
下图是所有用到 triggerEffects
函数的地方:
dep
参数不可能是Array
,而且dep
是Set
对象,可以直接for of
遍历。
export function triggerEffects(
dep: Dep | ReactiveEffect[],
debuggerEventExtraInfo?: DebuggerEventExtraInfo
) {
// spread into array for stabilization
const effects = isArray(dep) ? dep : [...dep]
for (const effect of effects) {
if (effect.computed) {
triggerEffect(effect, debuggerEventExtraInfo)
}
}
for (const effect of effects) {
if (!effect.computed) {
triggerEffect(effect, debuggerEventExtraInfo)
}
}
}
What does the proposed API look like?
export function triggerEffects(
dep: Dep,
debuggerEventExtraInfo?: DebuggerEventExtraInfo
) {
for (const effect of dep) {
if (effect.computed) {
triggerEffect(effect, debuggerEventExtraInfo)
}
}
for (const effect of dep) {
if (!effect.computed) {
triggerEffect(effect, debuggerEventExtraInfo)
}
}
}