refactor(ivy): misc (#25174)

PR Close #25174
This commit is contained in:
Victor Berchet 2018-07-29 14:35:05 -07:00 committed by Igor Minar
parent cd89eb8404
commit 36648293a8
4 changed files with 21 additions and 17 deletions

View File

@ -11,7 +11,7 @@
import {ChangeDetectorRef as viewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref'; import {ChangeDetectorRef as viewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref';
import {InjectionToken} from '../di/injection_token'; import {InjectionToken} from '../di/injection_token';
import {InjectFlags, Injector, inject, setCurrentInjector} from '../di/injector'; import {InjectFlags, Injector, NullInjector, inject, setCurrentInjector} from '../di/injector';
import * as viewEngine from '../linker'; import * as viewEngine from '../linker';
import {Type} from '../type'; import {Type} from '../type';
@ -636,20 +636,23 @@ class NodeInjector implements Injector {
class ViewContainerRef implements viewEngine.ViewContainerRef { class ViewContainerRef implements viewEngine.ViewContainerRef {
private _viewRefs: viewEngine.ViewRef[] = []; private _viewRefs: viewEngine.ViewRef[] = [];
constructor( constructor(
private _lContainerNode: LContainerNode, private _hostNode: LElementNode|LContainerNode) {} private _lContainerNode: LContainerNode, private _hostNode: LElementNode|LContainerNode) {}
get element(): ElementRef { return new ElementRef(this._hostNode.native); } get element(): ElementRef {
const injector = getOrCreateNodeInjectorForNode(this._hostNode);
return getOrCreateElementRef(injector);
}
get injector(): Injector { get injector(): Injector {
return new NodeInjector(getOrCreateNodeInjectorForNode(this._hostNode)); const injector = getOrCreateNodeInjectorForNode(this._hostNode);
return new NodeInjector(injector);
} }
/** @deprecated No replacement */ /** @deprecated No replacement */
get parentInjector(): Injector { get parentInjector(): Injector {
const parentLInjector = getParentLNode(this._hostNode).nodeInjector; const parentLInjector = getParentLNode(this._hostNode).nodeInjector;
return parentLInjector ? new NodeInjector(parentLInjector) : Injector.NULL; return parentLInjector ? new NodeInjector(parentLInjector) : new NullInjector();
} }
clear(): void { clear(): void {

View File

@ -336,7 +336,7 @@ export function createLViewData<T>(
null, // directives null, // directives
null, // cleanupInstances null, // cleanupInstances
context, // context context, // context
viewData && viewData[INJECTOR] || null, // injector viewData ? viewData[INJECTOR] : null, // injector
renderer, // renderer renderer, // renderer
sanitizer || null, // sanitizer sanitizer || null, // sanitizer
null, // tail null, // tail

View File

@ -26,6 +26,9 @@
{ {
"name": "ChangeDetectionStrategy" "name": "ChangeDetectionStrategy"
}, },
{
"name": "ChangeDetectorRef"
},
{ {
"name": "DECLARATION_VIEW" "name": "DECLARATION_VIEW"
}, },
@ -146,6 +149,9 @@
{ {
"name": "TVIEW" "name": "TVIEW"
}, },
{
"name": "TemplateRef"
},
{ {
"name": "TemplateRef$1" "name": "TemplateRef$1"
}, },
@ -180,7 +186,7 @@
"name": "VIEWS" "name": "VIEWS"
}, },
{ {
"name": "ViewContainerRef$1" "name": "ViewContainerRef"
}, },
{ {
"name": "ViewContainerRef$1" "name": "ViewContainerRef$1"

View File

@ -1039,10 +1039,8 @@ describe('ViewContainerRef', () => {
describe('getters', () => { describe('getters', () => {
it('should work on elements', () => { it('should work on elements', () => {
function createTemplate() { function createTemplate() {
elementStart(0, 'header', ['vcref', '']); element(0, 'header', ['vcref', '']);
elementEnd(); element(1, 'footer');
elementStart(1, 'footer');
elementEnd();
} }
new TemplateFixture(createTemplate, undefined, [DirectiveWithVCRef]); new TemplateFixture(createTemplate, undefined, [DirectiveWithVCRef]);
@ -1060,10 +1058,8 @@ describe('ViewContainerRef', () => {
createComponent('header-cmp', function(rf: RenderFlags, ctx: any) {}); createComponent('header-cmp', function(rf: RenderFlags, ctx: any) {});
function createTemplate() { function createTemplate() {
elementStart(0, 'header-cmp', ['vcref', '']); element(0, 'header-cmp', ['vcref', '']);
elementEnd(); element(1, 'footer');
elementStart(1, 'footer');
elementEnd();
} }
new TemplateFixture(createTemplate, undefined, [HeaderComponent, DirectiveWithVCRef]); new TemplateFixture(createTemplate, undefined, [HeaderComponent, DirectiveWithVCRef]);
@ -1079,8 +1075,7 @@ describe('ViewContainerRef', () => {
it('should work on containers', () => { it('should work on containers', () => {
function createTemplate() { function createTemplate() {
container(0, embeddedTemplate, undefined, ['vcref', '']); container(0, embeddedTemplate, undefined, ['vcref', '']);
elementStart(1, 'footer'); element(1, 'footer');
elementEnd();
} }
function updateTemplate() { function updateTemplate() {