Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
doc(module): add document for new module system and how to disable fe…
Browse files Browse the repository at this point in the history
…atures. (#777)
  • Loading branch information
JiaLiPassion authored and mhevery committed May 19, 2017
1 parent b7238c8 commit 7ad3070
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
65 changes: 65 additions & 0 deletions MODULE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Modules

zone.js patches the async APIs which described above, but those patch will have some overhead,
from zone.js v0.8.9, you can choose which web API module you want to patch, for example,
the below samples show how to disable some modules, you just need to define some global variables
before load zone.js.

```
<script>
__Zone_disable_Error = true; // Zone will not patch Error
__Zone_disable_on_property = true; // Zone will not patch onProperty such as button.onclick
__Zone_disable_geolocation = true; // Zone will not patch geolocation API
__Zone_disable_toString = true; // Zone will not patch Function.prototype.toString
__Zone_disable_blocking = true; // Zone will not patch alert/prompt/confirm
__Zone_disable_PromiseRejectionEvent = true; // Zone will not patch PromiseRejectionEventHandler
</script>
<script src="../dist/zone.js"></script>
```

Below is the full list of current support modules.

- Common

|Module Name|Behavior with zone.js patch|How to disable|
|--|--|--|
|Error|stack frames will have the Zone's name information, (By default, Error patch will not be loaded by zone.js)|__Zone_disable_Error = true|
|toString|Function.toString will be patched to return native version of toString|__Zone_disable_toString = true|
|ZoneAwarePromise|Promise.then will be patched as Zone aware MicroTask|__Zone_disable_ZoneAwarePromise = true|
|bluebird|Bluebird will use Zone.scheduleMicroTask as async scheduler. (By default, bluebird patch will not be loaded by zone.js)|__Zone_disable_bluebird = true|

- Browser

|Module Name|Behavior with zone.js patch|How to disable|
|--|--|--|
|on_property|target.onProp will become zone aware target.addEventListener(prop)|__Zone_disable_on_property = true|
|timers|setTimeout/setInterval/setImmediate will be patched as Zone MacroTask|__Zone_disable_timer = true|
|blocking|alert/prompt/confirm will be patched as Zone.run|__Zone_disable_blocking = true|
|EventTarget|target.addEventListener will be patched as Zone aware EventTask|__Zone_disable_EventTarget = true|
|XHR|XMLHttpRequest will be patched as Zone aware MacroTask|__Zone_disable_XHR = true|
|geolocation|navigator.geolocation's prototype will be patched as Zone.run|__Zone_disable_geolocation = true|
|PromiseRejectionEvent|PromiseRejectEvent will fire when ZoneAwarePromise has unhandled error|__Zone_disable_PromiseRejectionEvent = true|
|mediaQuery|mediaQuery addListener API will be patched as Zone aware EventTask. (By default, mediaQuery patch will not be loaded by zone.js) |__Zone_disable_mediaQuery = true|
|notification|notification onProperties API will be patched as Zone aware EventTask. (By default, notification patch will not be loaded by zone.js) |__Zone_disable_notification = true|

- NodeJS

|Module Name|Behavior with zone.js patch|How to disable|
|--|--|--|
|node_timers|NodeJS patch timer|__Zone_disable_node_timers = true|
|fs|NodeJS patch fs function as macroTask|__Zone_disable_fs = true|
|EventEmitter|NodeJS patch EventEmitter as Zone aware EventTask|__Zone_disable_EventEmitter = true|
|nextTick|NodeJS patch process.nextTick as microTask|__Zone_disable_nextTick = true|
|handleUnhandledPromiseRejection|NodeJS handle unhandledPromiseRejection from ZoneAwarePromise|__Zone_disable_handleUnhandledPromiseRejection = true|
|crypto|NodeJS patch crypto function as macroTask|__Zone_disable_crypto = true|

- Angular(2+)

Angular use zone.js to manage async operations and decide when to perform change detection, so in Angular,
the following APIs should be patched, otherwise Angular may not work as expected.

1. ZoneAwarePromise
2. timer
3. on_property
4. EventTarget
5. XHR
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ more details.
And now we are adding support to some non standard APIs, such as MediaQuery,
Notification. Please see [NON-STANDARD-APIS.md](NON-STANDARD-APIS.md) for more details.

## Modules

zone.js patches the async APIs which described above, but those patch will have some overhead,
from zone.js v0.8.9, you can choose which web API module you want to patch, for detail, please
see [MODULE.md](MODULE.md) for more details.

## Promise A+ test passed
[![Promises/A+ 1.1 compliant](https://promisesaplus.com/assets/logo-small.png)](https://promisesaplus.com/)

Expand Down

0 comments on commit 7ad3070

Please sign in to comment.