feat(core): make ngprobe tokens pluggable
This commit is contained in:
parent
947f9c3f56
commit
f48142e679
|
@ -25,7 +25,7 @@ export * from './src/web_workers/shared/message_bus';
|
|||
export {WORKER_APP_LOCATION_PROVIDERS} from './src/web_workers/worker/location_providers';
|
||||
export {WORKER_UI_LOCATION_PROVIDERS} from './src/web_workers/ui/location_providers';
|
||||
|
||||
export {NgProbeToken} from './src/dom/debug/ng_probe';
|
||||
export * from './src/worker_render';
|
||||
export * from './src/worker_app';
|
||||
|
||||
export * from './private_export';
|
||||
export * from './private_export';
|
|
@ -6,9 +6,10 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ApplicationRef, DebugNode, NgZone, RootRenderer, getDebugNode, isDevMode} from '@angular/core';
|
||||
import {ApplicationRef, DebugNode, NgZone, Optional, RootRenderer, getDebugNode, isDevMode} from '@angular/core';
|
||||
|
||||
import {DebugDomRootRenderer} from '../../../core_private';
|
||||
import {StringMapWrapper} from '../../facade/collection';
|
||||
import {getDOM} from '../dom_adapter';
|
||||
import {DomRootRenderer} from '../dom_renderer';
|
||||
|
||||
|
@ -30,24 +31,44 @@ export function inspectNativeElement(element: any /** TODO #9100 */): DebugNode
|
|||
return getDebugNode(element);
|
||||
}
|
||||
|
||||
export function _createConditionalRootRenderer(rootRenderer: any /** TODO #9100 */) {
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export class NgProbeToken {
|
||||
constructor(private name: string, private token: any) {}
|
||||
}
|
||||
|
||||
export function _createConditionalRootRenderer(
|
||||
rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[]) {
|
||||
if (isDevMode()) {
|
||||
return _createRootRenderer(rootRenderer);
|
||||
return _createRootRenderer(rootRenderer, extraTokens);
|
||||
}
|
||||
return rootRenderer;
|
||||
}
|
||||
|
||||
function _createRootRenderer(rootRenderer: any /** TODO #9100 */) {
|
||||
function _createRootRenderer(rootRenderer: any /** TODO #9100 */, extraTokens: NgProbeToken[]) {
|
||||
getDOM().setGlobalVar(INSPECT_GLOBAL_NAME, inspectNativeElement);
|
||||
getDOM().setGlobalVar(CORE_TOKENS_GLOBAL_NAME, CORE_TOKENS);
|
||||
getDOM().setGlobalVar(
|
||||
CORE_TOKENS_GLOBAL_NAME,
|
||||
StringMapWrapper.merge(CORE_TOKENS, _ngProbeTokensToMap(extraTokens || [])));
|
||||
return new DebugDomRootRenderer(rootRenderer);
|
||||
}
|
||||
|
||||
function _ngProbeTokensToMap(tokens: NgProbeToken[]): {[name: string]: any} {
|
||||
return tokens.reduce((prev: any, t: any) => (prev[t.name] = t.token, prev), {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Providers which support debugging Angular applications (e.g. via `ng.probe`).
|
||||
*/
|
||||
export const ELEMENT_PROBE_PROVIDERS: any[] =
|
||||
[{provide: RootRenderer, useFactory: _createConditionalRootRenderer, deps: [DomRootRenderer]}];
|
||||
export const ELEMENT_PROBE_PROVIDERS: any[] = [{
|
||||
provide: RootRenderer,
|
||||
useFactory: _createConditionalRootRenderer,
|
||||
deps: [DomRootRenderer, [NgProbeToken, new Optional()]]
|
||||
}];
|
||||
|
||||
export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] =
|
||||
[{provide: RootRenderer, useFactory: _createRootRenderer, deps: [DomRootRenderer]}];
|
||||
export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = [{
|
||||
provide: RootRenderer,
|
||||
useFactory: _createRootRenderer,
|
||||
deps: [DomRootRenderer, [NgProbeToken, new Optional()]]
|
||||
}];
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgProbeToken} from '@angular/platform-browser';
|
||||
import {Router} from './src/router';
|
||||
|
||||
export const ROUTER_NG_PROBE_PROVIDER = {
|
||||
provide: NgProbeToken,
|
||||
multi: true,
|
||||
useValue: new NgProbeToken('router', Router)
|
||||
};
|
|
@ -126,6 +126,11 @@ export interface MessageBusSource {
|
|||
initChannel(channel: string, runInZone: boolean): void;
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
export declare class NgProbeToken {
|
||||
constructor(name: string, token: any);
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
export declare const platformBrowser: (extraProviders?: any[]) => PlatformRef;
|
||||
|
||||
|
|
Loading…
Reference in New Issue