Files
Angular-Cn/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts
T
Tobias Bosch 0fa3895d5b feat(compiler): implement style encapsulation for new view engine (#14518)
Included refactoring:
- splits the `RendererV2` into a `RendererFactoryV2` and a `RendererV2`
- makes the `DebugRendererV2` a private class in `@angular/core`
- remove `setBindingDebugInfo` from `RendererV2`, but rename `RendererV2.setText` to 
  `RendererV2.setValue` and allow it on comments and text nodes.

Part of #14013
2017-02-16 13:55:55 -08:00

74 lines
2.2 KiB
TypeScript

/**
* @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 * as core from '@angular/core';
import {StringMapWrapper} from '../../facade/collection';
import {DebugDomRootRenderer} from '../../private_import_core';
import {getDOM} from '../dom_adapter';
import {DomRendererFactoryV2, DomRootRenderer} from '../dom_renderer';
const CORE_TOKENS = {
'ApplicationRef': core.ApplicationRef,
'NgZone': core.NgZone,
};
const INSPECT_GLOBAL_NAME = 'ng.probe';
const CORE_TOKENS_GLOBAL_NAME = 'ng.coreTokens';
/**
* Returns a {@link DebugElement} for the given native DOM element, or
* null if the given native element does not have an Angular view associated
* with it.
*/
export function inspectNativeElement(element: any): core.DebugNode {
return core.getDebugNode(element);
}
/**
* Deprecated. Use the one from '@angular/core'.
* @deprecated
*/
export class NgProbeToken {
constructor(public name: string, public token: any) {}
}
export function _createConditionalRootRenderer(
rootRenderer: any, extraTokens: NgProbeToken[], coreTokens: core.NgProbeToken[]) {
return core.isDevMode() ?
_createRootRenderer(rootRenderer, (extraTokens || []).concat(coreTokens || [])) :
rootRenderer;
}
function _createRootRenderer(rootRenderer: any, extraTokens: NgProbeToken[]) {
getDOM().setGlobalVar(INSPECT_GLOBAL_NAME, inspectNativeElement);
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: core.Provider[] = [
{
provide: core.RootRenderer,
useFactory: _createConditionalRootRenderer,
deps: [
DomRootRenderer,
[NgProbeToken, new core.Optional()],
[core.NgProbeToken, new core.Optional()],
],
},
];