136 Followers
·
Follow

Image for post
Image for post

Overview

In the previous article, we talked about the basic monkey-patch mechanism of Zone.js, In this article, we will go deep into another very important concept of Zone.js, which is async operations lifecycle hooks, with those hooks, Zone can monitor and intercept all lifecycles of async operations.

It is easy to explain with code sample.

This is a very simple code sample to explain how Zone.js intercept the lifecycle events of setTimeout, here we fork a new zone named zone with three callbacks.

  1. onScheduleTask , this callback will be called before async operation is scheduled , that means when the async operation is about to sent to browser(or NodeJS) to be scheduled to run later. …


Image for post
Image for post

Zone.js is a JavaScript library which implements Zones . It is inspired by Dart and created by Brian Ford, now Zone.js is used in Angular2+ to manage async operations.

From two years ago, I began to contribute to Zone.js , and now I am the collaborator and basically take charge of everything of Zone.js. Zone.js is a very powerful tool, I really love it and want to introduce this library to more users. So I will write a series of articles to introduce how Zone.js works under the hood, and how to use Zone.js in real life project.

What Zone.js can do

  1. Provide execution context between the async…

About

Jia Li

Programmer with passion, core contributor of zone.js

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store