forked from angular/zone.js
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…lib to configure root zone
- Loading branch information
1 parent
e1df4bc
commit 961f3a2
Showing
3 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
Zone.__load_patch( | ||
"customize-root", | ||
(global: any, Zone: ZoneType, api: _ZonePrivate) => { | ||
// add a helper utility to let user to customize root zone | ||
// this is not by design, and will not be included in future | ||
// tc39 zone proposal, it just for test and may change in the future | ||
const customizeRootZone = global[api.symbol("customizeRootZone")]; | ||
if (!customizeRootZone) { | ||
return; | ||
} | ||
const currentDesc = Object.getOwnPropertyDescriptor(Zone, "current"); | ||
if (!currentDesc) { | ||
return; | ||
} | ||
const currentDescGet = currentDesc.get; | ||
if (!currentDescGet) { | ||
return; | ||
} | ||
const rootZone = Zone.root; | ||
Object.defineProperty(Zone, "current", { | ||
configurable: true, | ||
enumerable: true, | ||
get: function() { | ||
const currentZone = currentDescGet.apply(this, arguments); | ||
if (currentZone === rootZone) { | ||
return customizeRootZone; | ||
} | ||
return currentZone; | ||
} | ||
}); | ||
} | ||
); |