11# Zone.js's support for non standard apis
22
33Zone.js patched most standard APIs such as DOM event listeners, XMLHttpRequest in Browser, EventEmitter and fs API in Node.js so they can be in zone.
4-
5- But there are still a lot of non standard APIs that are not patched by default, such as MediaQuery, Notification,
6- WebAudio and so on. We are adding support to those APIs, and our progress is updated here.
7-
8- ## Currently supported non standard Web APIs
4+
5+ But there are still a lot of non standard APIs that are not patched by default, such as MediaQuery, Notification,
6+ WebAudio and so on. We are adding support to those APIs, and our progress is updated here.
7+
8+ ## Currently supported non standard Web APIs
99
1010* MediaQuery
11- * Notification
11+ * Notification
1212
1313## Currently supported polyfills
1414
2828
2929* bluebird promise
3030
31- Browser Usage:
31+ Browser Usage:
3232
3333```
3434 <script src="zone.js"></script>
@@ -75,11 +75,11 @@ remove the comment of the following line
7575
7676## Others
7777
78- * Cordova
78+ * Cordova
7979
8080patch ` cordova.exec ` API
8181
82- ` cordova.exec(success, error, service, action, args); `
82+ ` cordova.exec(success, error, service, action, args); `
8383
8484` success ` and ` error ` will be patched with ` Zone.wrap ` .
8585
@@ -96,12 +96,12 @@ to load the patch, you should load in the following order.
9696By default, those APIs' support will not be loaded in zone.js or zone-node.js,
9797so if you want to load those API's support, you should load those files by yourself.
9898
99- For example, if you want to add MediaQuery patch, you should do like this:
99+ For example, if you want to add MediaQuery patch, you should do like this:
100100
101101```
102- <script src="path/zone.js"></script>
103- <script src="path/webapis-media-query.js"></script>
104- ```
102+ <script src="path/zone.js"></script>
103+ <script src="path/webapis-media-query.js"></script>
104+ ```
105105
106106* rxjs
107107
@@ -127,28 +127,28 @@ constructorZone.run(() => {
127127
128128subscriptionZone.run(() => {
129129 observable.subscribe(() => {
130- console.log('current zone when subscription next', Zone.current.name); // will output subscription.
130+ console.log('current zone when subscription next', Zone.current.name); // will output subscription.
131131 }, () => {
132- console.log('current zone when subscription error', Zone.current.name); // will output subscription.
132+ console.log('current zone when subscription error', Zone.current.name); // will output subscription.
133133 }, () => {
134- console.log('current zone when subscription complete', Zone.current.name); // will output subscription.
134+ console.log('current zone when subscription complete', Zone.current.name); // will output subscription.
135135 });
136136});
137137
138138operatorZone.run(() => {
139139 observable.map(() => {
140- console.log('current zone when map operator', Zone.current.name); // will output operator.
140+ console.log('current zone when map operator', Zone.current.name); // will output operator.
141141 });
142142});
143143```
144144
145145Currently basically everything the ` rxjs ` API includes
146146
147- - Observable
148- - Subscription
149- - Subscriber
150- - Operators
151- - Scheduler
147+ * Observable
148+ * Subscription
149+ * Subscriber
150+ * Operators
151+ * Scheduler
152152
153153is patched, so each asynchronous call will run in the correct zone.
154154
@@ -194,7 +194,7 @@ user need to patch `io` themselves just like following code.
194194 < / script>
195195```
196196
197- please reference the sample repo [ zone-socketio] ( https://github.com/JiaLiPassion/zone-socketio ) about
197+ please reference the sample repo [ zone-socketio] ( https://github.com/JiaLiPassion/zone-socketio ) about
198198detail usage.
199199
200200* jsonp
@@ -208,14 +208,15 @@ there is a sampel repo [zone-jsonp](https://github.com/JiaLiPassion/test-zone-js
208208sample usage is:
209209
210210``` javascript
211- import ' zone.js/dist/zone-patch-jsonp' ;
212- Zone[' __zone_symbol__jsonp' ]({
211+ import " zone.js/dist/zone-patch-jsonp" ;
212+ Zone[" __zone_symbol__jsonp" ]({
213213 jsonp: getJSONP,
214- sendFuncName: ' send' ,
215- successFuncName: ' jsonpSuccessCallback' ,
216- failedFuncName: ' jsonpFailedCallback'
214+ sendFuncName: " send" ,
215+ successFuncName: " jsonpSuccessCallback" ,
216+ failedFuncName: " jsonpFailedCallback"
217217});
218218```
219+
219220* ResizeObserver
220221
221222Currently only ` Chrome 64 ` native support this feature.
@@ -227,3 +228,28 @@ import 'zone.js/dist/zone-patch-resize-observer';
227228```
228229
229230there is a sample repo [ zone-resize-observer] ( https://github.com/JiaLiPassion/zone-resize-observer ) here
231+
232+ * customize root zone
233+
234+ In some application, especially for performance test or async tracing, user may want a predefined root zone.
235+ For example,i when you include ` google map ` into ` index.html ` by adding ` script tag ` such as
236+ ` <script src="https://maps.googleapis.com/maps/api/js?key=KEY"></script> ` , ` google map js ` will add some event
237+ listeners or do some async operations during loading the js file, all those operations happens in ` root zone ` ,
238+ if we want to intercept those async operations, we need to modify root zone.
239+
240+ You can do like this:
241+
242+ ``` javascript
243+ < script src= " folder/zone.js" / >
244+ < script>
245+ var customizeRootZone = Zone .current .fork ({
246+ name: ' myRoot'
247+ });
248+ window .__zone_symbol__customizeRootZone = customizeRootZone;
249+ < / script>
250+ < script src= " folder/zone-patch-customize-root-zone.js" / >
251+ ```
252+
253+ ** Remind, this is not a public api or formal feature of zone.js, it will not be included in future tc39 proposal,
254+ and it is not by design, it is just a helper method to let you customize rootZone for some test and suppose to change
255+ in the future, please use it on your own risk**
0 commit comments