Angular2源码解读之ChangeDetection
来源:互联网 发布:阿里云域名空间备案 编辑:程序博客网 时间:2024/06/06 13:57
https://github.com/Leooman/Angular
ChangeDetectionStrategy
Describes within the change detector which strategy will be used the next time change detection is triggered.
- OnPush = 0
OnPush
means that the change detector’s mode will be set to CheckOnce
during hydration.
- Default = 1
Default
means that the change detector’s mode will be set to CheckAlways
during hydration
ChangeDetectorStatus
Describes the status of the detector
- CheckOnce = 0
CheckedOnce
means that after calling detectChanges the mode of the change detector will become Checked
.
- Checked = 1
Checked
means that the change detector should be skipped until its mode changes to CheckOnce
- CheckAlways = 2
CheckAlways
means that after calling detectChanges the mode of the change detector will remain CheckAlways
- Detached = 3
Detached
means that the change detector sub tree is not a part of the main tree and should be skipped
- Errored = 4
Errored
means that the change detector encountered an error checking a binding or calling a directive lifecycle method and is now in an inconsistent state. Change detectors in this state will no longer detect changes.
- Destroyed = 5
Destroyed
means that the change detector is destroyed
ChangeDetectorRef
object method
export class ChangeDetectorRef { markForCheck(): void, detach(): void, detectChanges(): void, checkNoChanges(): void, reattach(): void}
markForCheck
Marks all {@link ChangeDetectionStrategy#OnPush} ancestors as to be checked.
Example
detach
Detaches the change detector from the change detector tree.
The detached change detector will not be checked until it is reattached.
This can also be used in combination with {@link ChangeDetectorRef#detectChanges} to implement local change detection checks.
detectChanges
Checks the change detector and its children.
This can also be used in combination with {@link ChangeDetectorRef#detach} to implement local change detection checks.
Example
For performance reasons,we want to check and update the list every five seconds. We can do that by detaching the component’s change detector and doing a local check every five seconds.
checkNoChanges
Checks the change detector and its children, and throws if any changes are detected.
This is used in development mode to verify that running change detection doesn’t introduce other changes.
reattach
Reattach the change detector to the change detector tree.
This also marks OnPush ancestors as to be checked. This reattached change detector will be checked during the next change detection run.
Example
- Angular2源码解读之ChangeDetection
- Angular2源码解读之Directive
- Angular2源码解读之Component
- changedetection
- 源码解读之Intent解读
- 源码解读----之-----KMeans
- JBPM源码解读之:Fork
- postgres 源码解读之 toast
- nodeJS之eventproxy源码解读
- java源码解读之Vector
- java源码解读之stack
- Netty源码解读之线程
- JDK源码解读之RegularEnumSet
- Netty源码解读之线程
- Opencv 源码解读之 ImageEncoder
- 解读SDWebImage源码之UIImageView
- RxJava之just源码解读
- SDWebImage源码解读 之SDWebImageCompat
- LeetCode 543. Diameter of Binary Tree
- bfs和dfs:poj2386和leetcode130
- linux 使用jrtplib收发h.264视频文件
- 无法打开输入文件“libcaffe.lib” 解决方法
- SpringMVC简单注解实例--简要调用过程
- Angular2源码解读之ChangeDetection
- angular.copy()
- Java RandomAccessFile用法
- vim实现两个文件之间的复制
- Java设计模式《十九》命令模式
- C++派生类的构造函数和析构函数
- Android模拟点击屏幕,实现按键精灵点击屏幕功能
- C/C++内存管理机制
- Codefroces 410 A. Mike and palindrome