#117·mini-vue

trackEffects()方法,会有‘循环引用’ (不知道这个词是否恰当)吗?

Author: TomLongJoyCreated Apr 11, 2024Updated Apr 23, 2024

image export function trackEffects(dep) { //看看 dep 之前有没有添加过,添加过的话 那么就不添加了 if (dep.has(activeEffect)) return; dep.add(activeEffect) activeEffect.deps.push(dep); // 反向搜集

// start --- test 
let count = 0;
if( activeEffect.deps.length ){
    testMethod(activeEffect);
}
function testMethod(activeEffect){
    const dep = activeEffect.deps[0]
    for (const effect of dep) {            // debugger
        count++;
        if(count > 1000){
            debugger
            console.log('循环结束')
            return;
        }
        testMethod(effect);
        
    }
}
// end -- test 

}