• Zone 其實是來自於Dart 語言的特性
• Zones are actually a language feature in Dart.
• Dart 也只是編譯成 JavaScript
• Dart also just compiles to JavaScript
• 因此我們也可以使用 JavaScript 實作一樣的功能
• We can implement the same functionality in JavaScript too.
Zone 是啥?
13.
• Zone 是一個非同步處理的執行環境( Execution Context )
• An execution context for asynchronous operations.
• 對於錯誤處理和分析非常實用 ( 透過 hooks )
• Useful for things like error handling and profiling.
所以 Zone 到底能幹嘛?
• 是一個可注入的服務 (Aninjectable service )
• 用於效能調教 ( Optimize performance )
• 執行一個或多個非同步處理且不需更新 UI ( Change Detection )
• when starting a work consisting of one or more asynchronous tasks that
don't require UI updates
• 若有錯誤需要 Angular 協助處理
• Error handling to be handled by Angular.
NgZone
17.
• 執行的工作要被排除在外可用 runOutsideAngular
•Tasks can be kicked off via runOutsideAngular
• 若有需要,一些 tasks 可用 run 再次進入 Angular Zone
• If needed, these tasks can reenter the Angular zone via run.
NgZone
• Understanding zones
•Using Zones in angular for better performance
• Zones in angular
• What the heck is the event loop anyway?
• Understanding Zones and Change Detection in Ionic 2 & Angular 2
• Angular 2とZone.jsとテストの話
• Angular.io – NgZone
• Event Loop Demo Page
• Demo Source - GitHub
Reference