zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Angular jasmine单元测试框架fixture.detectChanges的实现原理

Angular框架原理 实现 单元测试 fixture Jasmine
2023-09-14 09:04:02 时间

源代码:

fixture的类型是component-fixture,里面会调用_tick方法:

具体执行的detectChange逻辑,取决于Change Detect reference:

RootViewRef,执行view方面的change detect:

class RootViewRef extends ViewRef {
    constructor(_view) {
        super(_view);
        this._view = _view;
    }
    detectChanges() {
        detectChangesInRootView(this._view);
    }
    checkNoChanges() {
        checkNoChangesInRootView(this._view);
    }
    get context() {
        return null;
    }
}

tickRootContext里要执行RenderComponentOrTemplate:

最后进入RefreshView的执行:

更多Jerry的原创文章,尽在:“汪子熙”: