Skip to content

Commit

Permalink
fix(promise): fix angular#891, sometimes NativePromise will not ready…
Browse files Browse the repository at this point in the history
…, and reduce zone.js size (angular#916)
  • Loading branch information
JiaLiPassion authored and mhevery committed Oct 3, 2017
1 parent e5fa562 commit 326a07f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export function patchEventTarget(
const captureTasks = target[symbolCaptureEventName];

if (tasks) {
const removeTasks = [...tasks];
const removeTasks = tasks.slice();
for (let i = 0; i < removeTasks.length; i++) {
const task = removeTasks[i];
let delegate = task.originalDelegate ? task.originalDelegate : task.callback;
Expand All @@ -540,7 +540,7 @@ export function patchEventTarget(
}

if (captureTasks) {
const removeTasks = [...captureTasks];
const removeTasks = captureTasks.slice();
for (let i = 0; i < removeTasks.length; i++) {
const task = removeTasks[i];
let delegate = task.originalDelegate ? task.originalDelegate : task.callback;
Expand Down
3 changes: 2 additions & 1 deletion lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
let resolve: (v: any) => void;
let reject: (v: any) => void;
let promise: any = new this((res, rej) => {
[resolve, reject] = [res, rej];
resolve = res;
reject = rej;
});
function onResolve(value: any) {
promise && (promise = null || resolve(value));
Expand Down
7 changes: 6 additions & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,12 @@ const Zone: ZoneType = (function(global: any) {
patchOnProperties: noop,
patchMethod: () => noop,
setNativePromise: (NativePromise: any) => {
nativeMicroTaskQueuePromise = NativePromise.resolve(0);
// sometimes NativePromise.resolve static function
// is not ready yet, (such as core-js/es6.promise)
// so we need to check here.
if (NativePromise && typeof NativePromise.resolve === FUNCTION) {
nativeMicroTaskQueuePromise = NativePromise.resolve(0);
}
},
};
let _currentZoneFrame: _ZoneFrame = {parent: null, zone: new Zone(null, null)};
Expand Down
1 change: 1 addition & 0 deletions tsconfig-esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"inlineSourceMap": false,
"inlineSources": false,
"declaration": true,
"downlevelIteration": false,
"noEmitOnError": false,
"stripInternal": true,
"sourceMap": true,
Expand Down

0 comments on commit 326a07f

Please sign in to comment.