Skip to content

Commit c2fae72

Browse files
vsavkinvicb
authored andcommitted
feat(router): register router with ngprobe
1 parent 7908679 commit c2fae72

8 files changed

Lines changed: 72 additions & 48 deletions

File tree

modules/@angular/core/src/application_ref.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ export function isDevMode(): boolean {
6060
return _devMode;
6161
}
6262

63+
/**
64+
* A token for third-party components that can register themselves with NgProbe.
65+
*
66+
* @experimental
67+
*/
68+
export class NgProbeToken {
69+
constructor(public name: string, public token: any) {}
70+
}
71+
6372
/**
6473
* Creates a platform.
6574
* Platforms have to be eagerly created via this function.

modules/@angular/core/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
export * from './metadata';
1515
export * from './util';
1616
export * from './di';
17-
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory} from './application_ref';
17+
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory, NgProbeToken} from './application_ref';
1818
export {APP_ID, PACKAGE_ROOT_URL, PLATFORM_INITIALIZER, APP_BOOTSTRAP_LISTENER} from './application_tokens';
1919
export {APP_INITIALIZER, ApplicationInitStatus} from './application_init';
2020
export * from './zone';

modules/@angular/platform-browser/src/dom/debug/ng_probe.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ApplicationRef, DebugNode, NgZone, Optional, Provider, RootRenderer, getDebugNode, isDevMode} from '@angular/core';
9+
import * as core from '@angular/core';
1010

1111
import {StringMapWrapper} from '../../facade/collection';
1212
import {DebugDomRootRenderer} from '../../private_import_core';
1313
import {getDOM} from '../dom_adapter';
1414
import {DomRootRenderer} from '../dom_renderer';
1515

16-
1716
const CORE_TOKENS = {
18-
'ApplicationRef': ApplicationRef,
19-
'NgZone': NgZone
17+
'ApplicationRef': core.ApplicationRef,
18+
'NgZone': core.NgZone
2019
};
2120

2221
const INSPECT_GLOBAL_NAME = 'ng.probe';
@@ -27,21 +26,25 @@ const CORE_TOKENS_GLOBAL_NAME = 'ng.coreTokens';
2726
* null if the given native element does not have an Angular view associated
2827
* with it.
2928
*/
30-
export function inspectNativeElement(element: any /** TODO #9100 */): DebugNode {
31-
return getDebugNode(element);
29+
export function inspectNativeElement(element: any /** TODO #9100 */): core.DebugNode {
30+
return core.getDebugNode(element);
3231
}
3332

3433
/**
35-
* @experimental
34+
* Deprecated. Use the one from '@angular/core'.
35+
* @deprecated
3636
*/
3737
export class NgProbeToken {
38-
constructor(private name: string, private token: any) {}
38+
constructor(public name: string, public token: any) {}
3939
}
4040

41+
4142
export function _createConditionalRootRenderer(
42-
rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[]) {
43-
if (isDevMode()) {
44-
return _createRootRenderer(rootRenderer, extraTokens);
43+
rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[],
44+
coreTokens: core.NgProbeToken[]) {
45+
if (core.isDevMode()) {
46+
const tokens = (extraTokens || []).concat(coreTokens || []);
47+
return _createRootRenderer(rootRenderer, tokens);
4548
}
4649
return rootRenderer;
4750
}
@@ -61,14 +64,11 @@ function _ngProbeTokensToMap(tokens: NgProbeToken[]): {[name: string]: any} {
6164
/**
6265
* Providers which support debugging Angular applications (e.g. via `ng.probe`).
6366
*/
64-
export const ELEMENT_PROBE_PROVIDERS: Provider[] = [{
65-
provide: RootRenderer,
67+
export const ELEMENT_PROBE_PROVIDERS: core.Provider[] = [{
68+
provide: core.RootRenderer,
6669
useFactory: _createConditionalRootRenderer,
67-
deps: [DomRootRenderer, [NgProbeToken, new Optional()]]
68-
}];
69-
70-
export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = [{
71-
provide: RootRenderer,
72-
useFactory: _createRootRenderer,
73-
deps: [DomRootRenderer, [NgProbeToken, new Optional()]]
74-
}];
70+
deps: [
71+
DomRootRenderer, [NgProbeToken, new core.Optional()],
72+
[core.NgProbeToken, new core.Optional()]
73+
]
74+
}];

modules/@angular/router/src/router_module.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {APP_BASE_HREF, HashLocationStrategy, Location, LocationStrategy, PathLocationStrategy, PlatformLocation} from '@angular/common';
10-
import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_BOOTSTRAP_LISTENER, ApplicationRef, Compiler, ComponentRef, Inject, Injector, ModuleWithProviders, NgModule, NgModuleFactoryLoader, OpaqueToken, Optional, Provider, SkipSelf, SystemJsNgModuleLoader} from '@angular/core';
10+
import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_BOOTSTRAP_LISTENER, ApplicationRef, Compiler, ComponentRef, Inject, Injector, ModuleWithProviders, NgModule, NgModuleFactoryLoader, NgProbeToken, OpaqueToken, Optional, Provider, SkipSelf, SystemJsNgModuleLoader} from '@angular/core';
1111
import {Route, Routes} from './config';
1212
import {RouterLink, RouterLinkWithHref} from './directives/router_link';
1313
import {RouterLinkActive} from './directives/router_link_active';
@@ -40,29 +40,30 @@ export const ROUTER_CONFIGURATION = new OpaqueToken('ROUTER_CONFIGURATION');
4040
*/
4141
export const ROUTER_FORROOT_GUARD = new OpaqueToken('ROUTER_FORROOT_GUARD');
4242

43-
const pathLocationStrategy = {
44-
provide: LocationStrategy,
45-
useClass: PathLocationStrategy
46-
};
47-
const hashLocationStrategy = {
48-
provide: LocationStrategy,
49-
useClass: HashLocationStrategy
50-
};
51-
5243
export const ROUTER_PROVIDERS: Provider[] = [
53-
Location, {provide: UrlSerializer, useClass: DefaultUrlSerializer}, {
44+
Location,
45+
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
46+
{
5447
provide: Router,
5548
useFactory: setupRouter,
5649
deps: [
5750
ApplicationRef, UrlSerializer, RouterOutletMap, Location, Injector, NgModuleFactoryLoader,
5851
Compiler, ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()]
5952
]
6053
},
61-
RouterOutletMap, {provide: ActivatedRoute, useFactory: rootRoute, deps: [Router]},
62-
{provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader}, RouterPreloader, NoPreloading,
63-
PreloadAllModules, {provide: ROUTER_CONFIGURATION, useValue: {enableTracing: false}}
54+
RouterOutletMap,
55+
{provide: ActivatedRoute, useFactory: rootRoute, deps: [Router]},
56+
{provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader},
57+
RouterPreloader,
58+
NoPreloading,
59+
PreloadAllModules,
60+
{provide: ROUTER_CONFIGURATION, useValue: {enableTracing: false}},
6461
];
6562

63+
export function routerNgProbeToken() {
64+
return new NgProbeToken('Router', Router);
65+
}
66+
6667
/**
6768
* @whatItDoes Adds router directives and providers.
6869
*
@@ -76,10 +77,9 @@ export const ROUTER_PROVIDERS: Provider[] = [
7677
* `RouterModule.forChild`.
7778
*
7879
* * `forRoot` creates a module that contains all the directives, the given routes, and the router
79-
* service itself.
80+
* service itself.
8081
* * `forChild` creates a module that contains all the directives and the given routes, but does not
81-
* include
82-
* the router service.
82+
* include the router service.
8383
*
8484
* When registered at the root, the module should be used as follows
8585
*
@@ -134,12 +134,15 @@ export class RouterModule {
134134
return {
135135
ngModule: RouterModule,
136136
providers: [
137-
ROUTER_PROVIDERS, provideRoutes(routes), {
137+
ROUTER_PROVIDERS,
138+
provideRoutes(routes),
139+
{
138140
provide: ROUTER_FORROOT_GUARD,
139141
useFactory: provideForRootGuard,
140142
deps: [[Router, new Optional(), new SkipSelf()]]
141143
},
142-
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}}, {
144+
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
145+
{
143146
provide: LocationStrategy,
144147
useFactory: provideLocationStrategy,
145148
deps: [
@@ -151,8 +154,9 @@ export class RouterModule {
151154
useExisting: config && config.preloadingStrategy ? config.preloadingStrategy :
152155
NoPreloading
153156
},
154-
provideRouterInitializer()
155-
]
157+
{provide: NgProbeToken, multi: true, useFactory: routerNgProbeToken},
158+
provideRouterInitializer(),
159+
],
156160
};
157161
}
158162

@@ -196,7 +200,7 @@ export function provideForRootGuard(router: Router): any {
196200
export function provideRoutes(routes: Routes): any {
197201
return [
198202
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
199-
{provide: ROUTES, multi: true, useValue: routes}
203+
{provide: ROUTES, multi: true, useValue: routes},
200204
];
201205
}
202206

@@ -297,6 +301,6 @@ export function provideRouterInitializer() {
297301
useFactory: initialRouterNavigation,
298302
deps: [Router, ApplicationRef, RouterPreloader, ROUTER_CONFIGURATION]
299303
},
300-
{provide: APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER}
304+
{provide: APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER},
301305
];
302306
}

modules/benchmarks/src/tree/ng2_ftl/app.ngfactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ class AppModuleInjector extends import0.NgModuleInjector<import1.AppModule> {
154154
get _RootRenderer_20(): any {
155155
if ((this.__RootRenderer_20 == (null as any))) {
156156
(this.__RootRenderer_20 = import23._createConditionalRootRenderer(
157-
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any))));
157+
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any)),
158+
this.parent.get(import8.NgProbeToken, (null as any))));
158159
}
159160
return this.__RootRenderer_20;
160161
}

modules/benchmarks/src/tree/ng2_static_ftl/app.ngfactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ class AppModuleInjector extends import0.NgModuleInjector<import1.AppModule> {
154154
get _RootRenderer_20(): any {
155155
if ((this.__RootRenderer_20 == (null as any))) {
156156
(this.__RootRenderer_20 = import23._createConditionalRootRenderer(
157-
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any))));
157+
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any)),
158+
this.parent.get(import8.NgProbeToken, (null as any))));
158159
}
159160
return this.__RootRenderer_20;
160161
}

tools/public_api_guard/core/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ export declare abstract class NgModuleRef<T> {
599599
abstract onDestroy(callback: () => void): void;
600600
}
601601

602+
/** @experimental */
603+
export declare class NgProbeToken {
604+
name: string;
605+
token: any;
606+
constructor(name: string, token: any);
607+
}
608+
602609
/** @experimental */
603610
export declare class NgZone {
604611
hasPendingMacrotasks: boolean;

tools/public_api_guard/platform-browser/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export declare class HammerGestureConfig {
5858
buildHammer(element: HTMLElement): HammerInstance;
5959
}
6060

61-
/** @experimental */
61+
/** @deprecated */
6262
export declare class NgProbeToken {
63+
name: string;
64+
token: any;
6365
constructor(name: string, token: any);
6466
}
6567

0 commit comments

Comments
 (0)