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

Commit

Permalink
feat(Core): fix #910, add a flag to allow user to ignore duplicate Zo…
Browse files Browse the repository at this point in the history
…ne error (#1093)
  • Loading branch information
JiaLiPassion authored and mhevery committed Jul 3, 2018
1 parent bf88c34 commit a86c6d5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,21 @@ const Zone: ZoneType = (function(global: any) {
}
mark('Zone');
if (global['Zone']) {
throw new Error('Zone already loaded.');
// if global['Zone'] already exists (maybe zone.js was already loaded or
// some other lib also registered a global object named Zone), we may need
// to throw an error, but sometimes user may not want this error.
// For example,
// we have two web pages, page1 includes zone.js, page2 doesn't.
// and the 1st time user load page1 and page2, everything work fine,
// but when user load page2 again, error occurs because global['Zone'] already exists.
// so we add a flag to let user choose whether to throw this error or not.
// By default, if existing Zone is from zone.js, we will not throw the error.
if (global[('__zone_symbol__forceDuplicateZoneCheck')] === true ||
typeof global['Zone'].__symbol__ !== 'function') {
throw new Error('Zone already loaded.');
} else {
return global['Zone'];
}
}

class Zone implements AmbientZone {
Expand Down

0 comments on commit a86c6d5

Please sign in to comment.