2018-08-06 14:09:38 -07:00
|
|
|
/**
|
|
|
|
|
* @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 {Injector} from '../di/injector';
|
|
|
|
|
import {Renderer2, RendererType2} from '../render/api';
|
|
|
|
|
import {DebugContext} from '../view';
|
|
|
|
|
import {DebugRenderer2, DebugRendererFactory2} from '../view/services';
|
|
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
import {getHostComponent, getInjector, getLocalRefs, loadContext} from './discovery_utils';
|
|
|
|
|
import {DirectiveDef} from './interfaces/definition';
|
|
|
|
|
import {TNode, TNodeFlags} from './interfaces/node';
|
|
|
|
|
import {TVIEW} from './interfaces/view';
|
2018-08-06 14:09:38 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adapts the DebugRendererFactory2 to create a DebugRenderer2 specific for IVY.
|
|
|
|
|
*
|
|
|
|
|
* The created DebugRenderer know how to create a Debug Context specific to IVY.
|
|
|
|
|
*/
|
|
|
|
|
export class Render3DebugRendererFactory2 extends DebugRendererFactory2 {
|
|
|
|
|
createRenderer(element: any, renderData: RendererType2|null): Renderer2 {
|
|
|
|
|
const renderer = super.createRenderer(element, renderData) as DebugRenderer2;
|
2018-09-24 10:30:29 +02:00
|
|
|
renderer.debugContextFactory = (nativeElement: any) => new Render3DebugContext(nativeElement);
|
2018-08-06 14:09:38 -07:00
|
|
|
return renderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stores context information about view nodes.
|
|
|
|
|
*
|
|
|
|
|
* Used in tests to retrieve information those nodes.
|
|
|
|
|
*/
|
|
|
|
|
class Render3DebugContext implements DebugContext {
|
2018-09-24 10:30:29 +02:00
|
|
|
constructor(private _nativeNode: any) {}
|
2018-08-06 14:09:38 -07:00
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
get nodeIndex(): number|null { return loadContext(this._nativeNode).nodeIndex; }
|
2018-08-06 14:09:38 -07:00
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
get view(): any { return loadContext(this._nativeNode).lViewData; }
|
2018-08-06 14:09:38 -07:00
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
get injector(): Injector { return getInjector(this._nativeNode); }
|
2018-08-06 14:09:38 -07:00
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
get component(): any { return getHostComponent(this._nativeNode); }
|
2018-08-06 14:09:38 -07:00
|
|
|
|
|
|
|
|
get providerTokens(): any[] {
|
2018-09-24 10:30:29 +02:00
|
|
|
const lDebugCtx = loadContext(this._nativeNode);
|
|
|
|
|
const lViewData = lDebugCtx.lViewData;
|
|
|
|
|
const tNode = lViewData[TVIEW].data[lDebugCtx.nodeIndex] as TNode;
|
|
|
|
|
const directivesCount = tNode.flags & TNodeFlags.DirectiveCountMask;
|
|
|
|
|
|
|
|
|
|
if (directivesCount > 0) {
|
|
|
|
|
const directiveIdxStart = tNode.flags >> TNodeFlags.DirectiveStartingIndexShift;
|
|
|
|
|
const directiveIdxEnd = directiveIdxStart + directivesCount;
|
|
|
|
|
const viewDirectiveDefs = this.view[TVIEW].data;
|
|
|
|
|
const directiveDefs =
|
|
|
|
|
viewDirectiveDefs.slice(directiveIdxStart, directiveIdxEnd) as DirectiveDef<any>[];
|
|
|
|
|
|
|
|
|
|
return directiveDefs.map(directiveDef => directiveDef.type);
|
2018-08-06 14:09:38 -07:00
|
|
|
}
|
|
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
return [];
|
2018-08-06 14:09:38 -07:00
|
|
|
}
|
|
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
get references(): {[key: string]: any} { return getLocalRefs(this._nativeNode); }
|
2018-08-06 14:09:38 -07:00
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
// TODO(pk): check previous implementation and re-implement
|
|
|
|
|
get context(): any { throw new Error('Not implemented in ivy'); }
|
2018-08-06 14:09:38 -07:00
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
// TODO(pk): check previous implementation and re-implement
|
2018-08-06 14:09:38 -07:00
|
|
|
get componentRenderElement(): any { throw new Error('Not implemented in ivy'); }
|
|
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
// TODO(pk): check previous implementation and re-implement
|
2018-08-06 14:09:38 -07:00
|
|
|
get renderNode(): any { throw new Error('Not implemented in ivy'); }
|
|
|
|
|
|
2018-09-24 10:30:29 +02:00
|
|
|
// TODO(pk): check previous implementation and re-implement
|
2018-08-06 14:09:38 -07:00
|
|
|
logError(console: Console, ...values: any[]): void { console.error(...values); }
|
2018-08-29 13:52:03 -07:00
|
|
|
}
|