feat(router): register router with ngprobe

This commit is contained in:
vsavkin 2016-11-09 14:58:40 -08:00 committed by Victor Berchet
parent 7908679c4b
commit c2fae72bc6
8 changed files with 72 additions and 48 deletions

View File

@ -60,6 +60,15 @@ export function isDevMode(): boolean {
return _devMode;
}
/**
* A token for third-party components that can register themselves with NgProbe.
*
* @experimental
*/
export class NgProbeToken {
constructor(public name: string, public token: any) {}
}
/**
* Creates a platform.
* Platforms have to be eagerly created via this function.

View File

@ -14,7 +14,7 @@
export * from './metadata';
export * from './util';
export * from './di';
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory} from './application_ref';
export {createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory, NgProbeToken} from './application_ref';
export {APP_ID, PACKAGE_ROOT_URL, PLATFORM_INITIALIZER, APP_BOOTSTRAP_LISTENER} from './application_tokens';
export {APP_INITIALIZER, ApplicationInitStatus} from './application_init';
export * from './zone';

View File

@ -6,17 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ApplicationRef, DebugNode, NgZone, Optional, Provider, RootRenderer, getDebugNode, isDevMode} from '@angular/core';
import * as core from '@angular/core';
import {StringMapWrapper} from '../../facade/collection';
import {DebugDomRootRenderer} from '../../private_import_core';
import {getDOM} from '../dom_adapter';
import {DomRootRenderer} from '../dom_renderer';
const CORE_TOKENS = {
'ApplicationRef': ApplicationRef,
'NgZone': NgZone
'ApplicationRef': core.ApplicationRef,
'NgZone': core.NgZone
};
const INSPECT_GLOBAL_NAME = 'ng.probe';
@ -27,21 +26,25 @@ const CORE_TOKENS_GLOBAL_NAME = 'ng.coreTokens';
* null if the given native element does not have an Angular view associated
* with it.
*/
export function inspectNativeElement(element: any /** TODO #9100 */): DebugNode {
return getDebugNode(element);
export function inspectNativeElement(element: any /** TODO #9100 */): core.DebugNode {
return core.getDebugNode(element);
}
/**
* @experimental
* Deprecated. Use the one from '@angular/core'.
* @deprecated
*/
export class NgProbeToken {
constructor(private name: string, private token: any) {}
constructor(public name: string, public token: any) {}
}
export function _createConditionalRootRenderer(
rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[]) {
if (isDevMode()) {
return _createRootRenderer(rootRenderer, extraTokens);
rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[],
coreTokens: core.NgProbeToken[]) {
if (core.isDevMode()) {
const tokens = (extraTokens || []).concat(coreTokens || []);
return _createRootRenderer(rootRenderer, tokens);
}
return rootRenderer;
}
@ -61,14 +64,11 @@ function _ngProbeTokensToMap(tokens: NgProbeToken[]): {[name: string]: any} {
/**
* Providers which support debugging Angular applications (e.g. via `ng.probe`).
*/
export const ELEMENT_PROBE_PROVIDERS: Provider[] = [{
provide: RootRenderer,
export const ELEMENT_PROBE_PROVIDERS: core.Provider[] = [{
provide: core.RootRenderer,
useFactory: _createConditionalRootRenderer,
deps: [DomRootRenderer, [NgProbeToken, new Optional()]]
}];
export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = [{
provide: RootRenderer,
useFactory: _createRootRenderer,
deps: [DomRootRenderer, [NgProbeToken, new Optional()]]
}];
deps: [
DomRootRenderer, [NgProbeToken, new core.Optional()],
[core.NgProbeToken, new core.Optional()]
]
}];

View File

@ -7,7 +7,7 @@
*/
import {APP_BASE_HREF, HashLocationStrategy, Location, LocationStrategy, PathLocationStrategy, PlatformLocation} from '@angular/common';
import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_BOOTSTRAP_LISTENER, ApplicationRef, Compiler, ComponentRef, Inject, Injector, ModuleWithProviders, NgModule, NgModuleFactoryLoader, OpaqueToken, Optional, Provider, SkipSelf, SystemJsNgModuleLoader} from '@angular/core';
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';
import {Route, Routes} from './config';
import {RouterLink, RouterLinkWithHref} from './directives/router_link';
import {RouterLinkActive} from './directives/router_link_active';
@ -40,17 +40,10 @@ export const ROUTER_CONFIGURATION = new OpaqueToken('ROUTER_CONFIGURATION');
*/
export const ROUTER_FORROOT_GUARD = new OpaqueToken('ROUTER_FORROOT_GUARD');
const pathLocationStrategy = {
provide: LocationStrategy,
useClass: PathLocationStrategy
};
const hashLocationStrategy = {
provide: LocationStrategy,
useClass: HashLocationStrategy
};
export const ROUTER_PROVIDERS: Provider[] = [
Location, {provide: UrlSerializer, useClass: DefaultUrlSerializer}, {
Location,
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
{
provide: Router,
useFactory: setupRouter,
deps: [
@ -58,11 +51,19 @@ export const ROUTER_PROVIDERS: Provider[] = [
Compiler, ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()]
]
},
RouterOutletMap, {provide: ActivatedRoute, useFactory: rootRoute, deps: [Router]},
{provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader}, RouterPreloader, NoPreloading,
PreloadAllModules, {provide: ROUTER_CONFIGURATION, useValue: {enableTracing: false}}
RouterOutletMap,
{provide: ActivatedRoute, useFactory: rootRoute, deps: [Router]},
{provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader},
RouterPreloader,
NoPreloading,
PreloadAllModules,
{provide: ROUTER_CONFIGURATION, useValue: {enableTracing: false}},
];
export function routerNgProbeToken() {
return new NgProbeToken('Router', Router);
}
/**
* @whatItDoes Adds router directives and providers.
*
@ -76,10 +77,9 @@ export const ROUTER_PROVIDERS: Provider[] = [
* `RouterModule.forChild`.
*
* * `forRoot` creates a module that contains all the directives, the given routes, and the router
* service itself.
* service itself.
* * `forChild` creates a module that contains all the directives and the given routes, but does not
* include
* the router service.
* include the router service.
*
* When registered at the root, the module should be used as follows
*
@ -134,12 +134,15 @@ export class RouterModule {
return {
ngModule: RouterModule,
providers: [
ROUTER_PROVIDERS, provideRoutes(routes), {
ROUTER_PROVIDERS,
provideRoutes(routes),
{
provide: ROUTER_FORROOT_GUARD,
useFactory: provideForRootGuard,
deps: [[Router, new Optional(), new SkipSelf()]]
},
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}}, {
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
{
provide: LocationStrategy,
useFactory: provideLocationStrategy,
deps: [
@ -151,8 +154,9 @@ export class RouterModule {
useExisting: config && config.preloadingStrategy ? config.preloadingStrategy :
NoPreloading
},
provideRouterInitializer()
]
{provide: NgProbeToken, multi: true, useFactory: routerNgProbeToken},
provideRouterInitializer(),
],
};
}
@ -196,7 +200,7 @@ export function provideForRootGuard(router: Router): any {
export function provideRoutes(routes: Routes): any {
return [
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
{provide: ROUTES, multi: true, useValue: routes}
{provide: ROUTES, multi: true, useValue: routes},
];
}
@ -297,6 +301,6 @@ export function provideRouterInitializer() {
useFactory: initialRouterNavigation,
deps: [Router, ApplicationRef, RouterPreloader, ROUTER_CONFIGURATION]
},
{provide: APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER}
{provide: APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER},
];
}

View File

@ -154,7 +154,8 @@ class AppModuleInjector extends import0.NgModuleInjector<import1.AppModule> {
get _RootRenderer_20(): any {
if ((this.__RootRenderer_20 == (null as any))) {
(this.__RootRenderer_20 = import23._createConditionalRootRenderer(
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any))));
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any)),
this.parent.get(import8.NgProbeToken, (null as any))));
}
return this.__RootRenderer_20;
}

View File

@ -154,7 +154,8 @@ class AppModuleInjector extends import0.NgModuleInjector<import1.AppModule> {
get _RootRenderer_20(): any {
if ((this.__RootRenderer_20 == (null as any))) {
(this.__RootRenderer_20 = import23._createConditionalRootRenderer(
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any))));
this._DomRootRenderer_19, this.parent.get(import23.NgProbeToken, (null as any)),
this.parent.get(import8.NgProbeToken, (null as any))));
}
return this.__RootRenderer_20;
}

View File

@ -599,6 +599,13 @@ export declare abstract class NgModuleRef<T> {
abstract onDestroy(callback: () => void): void;
}
/** @experimental */
export declare class NgProbeToken {
name: string;
token: any;
constructor(name: string, token: any);
}
/** @experimental */
export declare class NgZone {
hasPendingMacrotasks: boolean;

View File

@ -58,8 +58,10 @@ export declare class HammerGestureConfig {
buildHammer(element: HTMLElement): HammerInstance;
}
/** @experimental */
/** @deprecated */
export declare class NgProbeToken {
name: string;
token: any;
constructor(name: string, token: any);
}