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

Commit ad37464

Browse files
committed
feat(bluebird): patch bluebird promise and treat it as microtask
1 parent 14c7a6f commit ad37464

File tree

8 files changed

+694
-0
lines changed

8 files changed

+694
-0
lines changed

NON-STANDARD-APIS.md

+35
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ But there are still a lot of non standard APIs are not patched by default, such
1313

1414
## Currently supported non standard node APIs
1515

16+
## Currently supported non standard common APIs
17+
18+
* bluebird promise
19+
20+
Browser Usage:
21+
22+
```
23+
<script src="zone.js"></script>
24+
<script>
25+
Zone[Zone['__symbol__']('bluebird')] = require('bluebird');
26+
</script>
27+
<script src="zone-bluebird.js"></script>
28+
```
29+
30+
Node Usage:
31+
32+
```
33+
require('zone-node.js');
34+
Zone[Zone['__symbol__']('bluebird')] = require('bluebird');
35+
require('zone-bluebird.js');
36+
```
37+
38+
To run the jasmine test cases of bluebird
39+
40+
```
41+
npm install bluebird
42+
```
43+
44+
then modify test/node_tests.ts
45+
remove the comment of the following line
46+
47+
```
48+
//import './extra/bluebird.spec';
49+
```
50+
1651
## Usage
1752

1853
By default, those APIs' support will not be loaded in zone.js or zone-node.js,

dist/zone-bluebird.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
(function (global, factory) {
9+
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
10+
typeof define === 'function' && define.amd ? define(factory) :
11+
(factory());
12+
}(this, (function () { 'use strict';
13+
14+
/**
15+
* @license
16+
* Copyright Google Inc. All Rights Reserved.
17+
*
18+
* Use of this source code is governed by an MIT-style license that can be
19+
* found in the LICENSE file at https://angular.io/license
20+
*/
21+
(function () {
22+
var __symbol__ = Zone['__symbol__'];
23+
var bluebird = Zone[__symbol__('bluebird')];
24+
if (bluebird) {
25+
patchBluebird(bluebird);
26+
}
27+
function patchBluebird(bluebird) {
28+
bluebird.setScheduler(function (fn) {
29+
Zone.current.scheduleMicroTask('bluebird', fn);
30+
});
31+
}
32+
})();
33+
34+
})));

dist/zone-bluebird.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ gulp.task('build/webapis-notification.js', ['compile-esm'], function(cb) {
9999
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.js', true, cb);
100100
});
101101

102+
gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
103+
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
104+
});
105+
106+
gulp.task('build/bluebird.min.js', ['compile-esm'], function(cb) {
107+
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.min.js', true, cb);
108+
});
109+
102110
gulp.task('build/jasmine-patch.js', ['compile-esm'], function(cb) {
103111
return generateScript('./lib/jasmine/jasmine.ts', 'jasmine-patch.js', false, cb);
104112
});
@@ -167,6 +175,8 @@ gulp.task('build', [
167175
'build/webapis-media-query.js',
168176
'build/webapis-notification.js',
169177
'build/zone-mix.js',
178+
'build/bluebird.js',
179+
'build/bluebird.min.js',
170180
'build/jasmine-patch.js',
171181
'build/jasmine-patch.min.js',
172182
'build/mocha-patch.js',

lib/extra/bluebird.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
(() => {
9+
const __symbol__ = Zone['__symbol__'];
10+
const bluebird = Zone[__symbol__('bluebird')];
11+
if (bluebird) {
12+
patchBluebird(bluebird);
13+
}
14+
function patchBluebird(bluebird) {
15+
bluebird.setScheduler((fn) => {
16+
Zone.current.scheduleMicroTask('bluebird', fn);
17+
});
18+
}
19+
})();

0 commit comments

Comments
 (0)