-
Notifications
You must be signed in to change notification settings - Fork 407
WIP(core): Proposal: can unload, reload patch modules #1073
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
@mhevery , @robwormald , I have send a message to you on twitter, and I also described the information here. In ng-conf, I described an idea about using I have created a repo here with some basic doc, and a live demo here , https://github-zmawnz.stackblitz.io/ the idea detail is here.AngularElementsA POC of In ng-conf 2018, robwormald described the use cases of
So my idea is add a
How it works
try {
Zone.__init__(); // monkey patch window APIs
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(ref => {
// Ensure Angular destroys itself on hot reloads.
if (window['ngRef']) {
window['ngRef'].destroy();
}
window['ngRef'] = ref;
// Otherise, log the boot error
})
.catch(err => console.error(err));
} finally {
Zone.__unloadAll_patch(); // detach the monkey patch, so all window APIs was restored to native one.
}
So monkey patched version of window API only exists inside Angular Elements Here is the demo link DEMO. In the demo, there is an angular Element with zone.js, and it will run inside of Please review, thank you very much! |
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
I am a bit confused. If I understand correctly this PR will remove the My concern is that the cost of patching and un-patching is way more than the cost of Do we have perf numbers that say this makes things better? |
@mhevery ,
yes, it will remove |
@mhevery , I did a benchmark test. for (let i = 0; i < 1000000; i++) {
zone.run(function () {});
} And by average,
|
This is a proposal to support
unload
,reload
patch.Use case: only run specified code into zone.
for example, in current version, the code above, the 1st setTimeout will run into
zone
, the 2nd will run intoroot Zone
. But evenroot
Zone still have performance impact. So we may want the 2nd totally run innative setTimeout
.in this PR proposal, only
patch
allmodules
such assetTimeout, XHR, promise
inzone.run
.and
unPatch
them whenin root zone
or by calling some method like 'runOutsideOfZone` explicitly.Use case: such as angular elements to implement WebComponent. Only run logic with
zone.js
patched inside `angular elements without impact outside world.Proposal. Auto patch when
zone.run
, Auto unpatch afterzone.run
. Auto repatch whenzone.run
again.To make
unPatch
andrePatch
faster, keeppatched delegate
andnative delegate
reference when callZone.__load_patch
, so we only resetdelegate
whenunPatch
andrePatch
.such as https://github.com/angular/zone.js/compare/master...JiaLiPassion:module?expand=1#diff-75082c639aefcc47b3b8df57c8870867R37
@mhevery , do you think this idea worth a discussion? Thank you.