Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In triggerEffects, it is not necessary to determine whether the dep parameter is an Array #8714

Closed
lv-z-l opened this issue Jul 4, 2023 · 0 comments · Fixed by #5912
Closed
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior.

Comments

@lv-z-l
Copy link

lv-z-l commented Jul 4, 2023

What problem does this feature solve?

triggerEffects 函数中,对 dep 的判断多余,将 dep:Set 展开到一个数组的操作多余。
下图是所有用到 triggerEffects 函数的地方:
image

dep 参数不可能是Array,而且depSet对象,可以直接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)
    }
  }
}
@lv-z-l lv-z-l added the ✨ feature request New feature or request label Jul 4, 2023
@Justineo Justineo added 🧹 p1-chore Priority 1: this doesn't change code behavior. and removed ✨ feature request New feature or request labels Jul 4, 2023
@lv-z-l lv-z-l closed this as completed Jul 5, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2023
yyx990803 pushed a commit that referenced this issue Oct 27, 2023
sxzz pushed a commit that referenced this issue Oct 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior.
Projects
None yet
2 participants