Reputation: 8731
I'm starting a student project which is a metric tool for angular2.
I'm actually working on the proof of concept, the proof that I can get metrics on a component at runtime only using a static register method myLibClass.registerComponents([Component1, Component2,...])
which would have an implementation like this one (pseudo-code):
registerComponents(components:any[]):void{
components.forEach(component => {
//Register metric methods on zone foreTask and afterTask
});
}
How can I get the global zone of angular2
? I want to bind my methods on ng2 zone in order to be able to check execution time for each call and NgZone does not provide the tools to do such a thing.
Another idea to metric a component from an external class is welcome too
I've done some researches and I found how to get the global angular2 zone using ̀ Zone.current`.
Problem is still here, since the second part of it (the hardest one) is not achieved yet:
I want to bind my methods on ng2 zone in order to be able to check execution time for each call and NgZone does not provide the tools to do such a thing.
The only way to do this would be to fork the angular2 zone and replace the actual zone used by angular by my forked one (That's the only way to do it I see).
Is it even possible? Forking the zone is not a problem but I can't connect it on angular2.
Since I need more informations than null
(as you can see on the source code of ngZone, every event fired is fired with null
, this doesn't allow me to get the informations I need about the last microtask like the name of the call or the caller), I need to have a custom zone which would be used by angular2, but I can't extend NgZone because it's not using DI for instanciation and thus the zone used by angular2 will still be NgZone.
Upvotes: 1
Views: 330
Reputation: 214195
If you want run application with overrided ngZone you can do the following trick.
const platform = platformBrowserDynamic();
const zone = new MyZone();
platform['_bootstrapModuleWithZone'](AppModule, [], zone);
It's used within ng1 upgrade adapter
but unfortunately it is private method
See also
Upvotes: 1