Skip to content

Commit 5a7bf36

Browse files
mheveryIgorMinar
authored andcommitted
build: fix circular dep between interface and l_node by merging (angular#20855)
PR Close angular#20855
1 parent 66528a2 commit 5a7bf36

File tree

17 files changed

+453
-434
lines changed

17 files changed

+453
-434
lines changed

modules/benchmarks/src/largetable/render3/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {ɵC as C, ɵE as E, ɵT as T, ɵV as V, ɵb as b, ɵc as c, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as detectChanges, ɵe as e, ɵs as s, ɵt as t, ɵv as v} from '@angular/core';
10-
import {ComponentDef} from '@angular/core/src/render3/public_interfaces';
10+
import {ComponentDef} from '@angular/core/src/render3/definition_interfaces';
1111

1212
import {TableCell, buildTable, emptyTable} from '../util';
1313

modules/benchmarks/src/tree/render3/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {ɵC as C, ɵD as D, ɵE as E, ɵT as T, ɵV as V, ɵb as b, ɵb1 as b1, ɵc as c, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵp as p, ɵs as s, ɵt as t, ɵv as v} from '@angular/core';
10-
import {ComponentDef} from '@angular/core/src/render3/public_interfaces';
10+
import {ComponentDef} from '@angular/core/src/render3/definition_interfaces';
1111

1212
import {TreeNode, buildTree, emptyTree} from '../util';
1313

packages/core/src/render3/component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
// We are temporarily importing the existing viewEngine from core so we can be sure we are
1010
// correctly implementing its interfaces for backwards compatibility.
11-
import * as viewEngine from '../core';
11+
import {Injector} from '../di/injector';
12+
import {ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
13+
import {EmbeddedViewRef as viewEngine_EmbeddedViewRef} from '../linker/view_ref';
1214

1315
import {assertNotNull} from './assert';
16+
import {ComponentDef, ComponentType} from './definition_interfaces';
1417
import {NG_HOST_SYMBOL, createError, createViewState, directive, enterView, hostElement, leaveView, locateHostElement, renderComponentOrTemplate} from './instructions';
15-
import {LElement} from './l_node';
16-
import {ComponentDef, ComponentType} from './public_interfaces';
18+
import {LElement} from './interfaces';
1719
import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from './renderer';
1820
import {notImplemented, stringify} from './util';
1921

@@ -32,7 +34,7 @@ export interface CreateComponentOptions {
3234
host?: RElement|string;
3335

3436
/** Module injector for the component. If unspecified, the injector will be NULL_INJECTOR. */
35-
injector?: viewEngine.Injector;
37+
injector?: Injector;
3638

3739
/**
3840
* List of features to be applied to the created component. Features are simply
@@ -51,7 +53,7 @@ export interface CreateComponentOptions {
5153
* @param options Optional parameters which control bootstrapping
5254
*/
5355
export function createComponentRef<T>(
54-
componentType: ComponentType<T>, opts: CreateComponentOptions): viewEngine.ComponentRef<T> {
56+
componentType: ComponentType<T>, opts: CreateComponentOptions): viewEngine_ComponentRef<T> {
5557
const component = renderComponent(componentType, opts);
5658
const hostView = createViewRef(() => detectChanges(component), component);
5759
return {
@@ -78,7 +80,7 @@ function createViewRef<T>(detectChanges: () => void, context: T): EmbeddedViewRe
7880
return addDestroyable(new EmbeddedViewRef(detectChanges), context);
7981
}
8082

81-
class EmbeddedViewRef<T> implements viewEngine.EmbeddedViewRef<T> {
83+
class EmbeddedViewRef<T> implements viewEngine_EmbeddedViewRef<T> {
8284
// TODO: rootNodes should be replaced when properly implemented
8385
rootNodes = null !;
8486
context: T;
@@ -147,7 +149,7 @@ function addDestroyable<T, C>(obj: any, context: C): T&DestroyRef<C> {
147149

148150

149151
// TODO: A hack to not pull in the NullInjector from @angular/core.
150-
export const NULL_INJECTOR: viewEngine.Injector = {
152+
export const NULL_INJECTOR: Injector = {
151153
get: (token: any, notFoundValue?: any) => {
152154
throw new Error('NullInjector: Not found: ' + stringify(token));
153155
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {RendererType2} from '../render/api';
10+
import {Type} from '../type';
11+
import {resolveRendererType2} from '../view/util';
12+
13+
import {ComponentDef, ComponentDefArgs, DirectiveDef, DirectiveDefArgs} from './definition_interfaces';
14+
import {componentRefresh, diPublic} from './instructions';
15+
16+
17+
18+
/**
19+
* Create a component definition object.
20+
*
21+
*
22+
* # Example
23+
* ```
24+
* class MyDirective {
25+
* // Generated by Angular Template Compiler
26+
* // [Symbol] syntax will not be supported by TypeScript until v2.7
27+
* static [COMPONENT_DEF_SYMBOL] = defineComponent({
28+
* ...
29+
* });
30+
* }
31+
* ```
32+
*/
33+
export function defineComponent<T>(componentDefinition: ComponentDefArgs<T>): ComponentDef<T> {
34+
const def = <ComponentDef<any>>{
35+
type: componentDefinition.type,
36+
diPublic: null,
37+
n: componentDefinition.factory,
38+
tag: (componentDefinition as ComponentDefArgs<T>).tag || null !,
39+
template: (componentDefinition as ComponentDefArgs<T>).template || null !,
40+
r: componentDefinition.refresh ||
41+
function(d: number, e: number) { componentRefresh(d, e, componentDefinition.template); },
42+
inputs: invertObject(componentDefinition.inputs),
43+
outputs: invertObject(componentDefinition.outputs),
44+
methods: invertObject(componentDefinition.methods),
45+
rendererType: resolveRendererType2(componentDefinition.rendererType) || null,
46+
};
47+
const feature = componentDefinition.features;
48+
feature && feature.forEach((fn) => fn(def));
49+
return def;
50+
}
51+
52+
export function NgOnChangesFeature<T>(definition: DirectiveDef<T>) {
53+
// TODO: implement. See: https://app.asana.com/0/443577627818617/465170715764659
54+
}
55+
56+
export function PublicFeature<T>(definition: DirectiveDef<T>) {
57+
definition.diPublic = diPublic;
58+
}
59+
60+
const EMPTY = {};
61+
62+
/** Swaps the keys and values of an object. */
63+
function invertObject(obj: any): any {
64+
if (obj == null) return EMPTY;
65+
const newObj: any = {};
66+
for (let minifiedKey in obj) {
67+
newObj[obj[minifiedKey]] = minifiedKey;
68+
}
69+
return newObj;
70+
}
71+
72+
/**
73+
* Create a directive definition object.
74+
*
75+
* # Example
76+
* ```
77+
* class MyDirective {
78+
* // Generated by Angular Template Compiler
79+
* // [Symbol] syntax will not be supported by TypeScript until v2.7
80+
* static [DIRECTIVE_DEF_SYMBOL] = defineDirective({
81+
* ...
82+
* });
83+
* }
84+
* ```
85+
*/
86+
export const defineDirective = defineComponent as<T>(directiveDefinition: DirectiveDefArgs<T>) =>
87+
DirectiveDef<T>;

packages/core/src/render3/public_interfaces.ts renamed to packages/core/src/render3/definition_interfaces.ts

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {RendererType2, Type} from '../core';
9+
import {RendererType2} from '../render/api';
10+
import {Type} from '../type';
1011
import {resolveRendererType2} from '../view/util';
11-
import {componentRefresh, diPublic} from './instructions';
1212

1313

1414

@@ -78,7 +78,7 @@ export interface DirectiveDef<T> {
7878
* @param directiveIndex index of the directive in the containing template
7979
* @param elementIndex index of an host element for a given directive.
8080
*/
81-
r(this: DirectiveDef<T>, directiveIndex: number, elementIndex: number): void;
81+
r(directiveIndex: number, elementIndex: number): void;
8282
}
8383

8484
export interface ComponentDef<T> extends DirectiveDef<T> {
@@ -93,7 +93,7 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
9393
* @param directiveIndex index of the directive in the containing template
9494
* @param elementIndex index of an host element for a given component.
9595
*/
96-
r(this: ComponentDef<T>, directiveIndex: number, elementIndex: number): void;
96+
r(directiveIndex: number, elementIndex: number): void;
9797

9898
/**
9999
* The tag name which should be used by the component.
@@ -120,7 +120,7 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
120120
export interface DirectiveDefArgs<T> {
121121
type: Type<T>;
122122
factory: () => T;
123-
refresh?: (this: DirectiveDef<T>, directiveIndex: number, elementIndex: number) => void;
123+
refresh?: (directiveIndex: number, elementIndex: number) => void;
124124
inputs?: {[P in keyof T]?: string};
125125
outputs?: {[P in keyof T]?: string};
126126
methods?: {[P in keyof T]?: string};
@@ -130,80 +130,10 @@ export interface DirectiveDefArgs<T> {
130130
export interface ComponentDefArgs<T> extends DirectiveDefArgs<T> {
131131
tag: string;
132132
template: ComponentTemplate<T>;
133-
refresh?: (this: ComponentDef<T>, directiveIndex: number, elementIndex: number) => void;
133+
refresh?: (directiveIndex: number, elementIndex: number) => void;
134134
features?: ComponentDefFeature[];
135135
rendererType?: RendererType2;
136136
}
137137

138138
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
139139
export type ComponentDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
140-
141-
/**
142-
* Create a component definition object.
143-
*
144-
*
145-
* # Example
146-
* ```
147-
* class MyDirective {
148-
* // Generated by Angular Template Compiler
149-
* // [Symbol] syntax will not be supported by TypeScript until v2.7
150-
* static [COMPONENT_DEF_SYMBOL] = defineComponent({
151-
* ...
152-
* });
153-
* }
154-
* ```
155-
*/
156-
export function defineComponent<T>(componentDefinition: ComponentDefArgs<T>): ComponentDef<T> {
157-
const def = <ComponentDef<any>>{
158-
type: componentDefinition.type,
159-
diPublic: null,
160-
n: componentDefinition.factory,
161-
tag: (componentDefinition as ComponentDefArgs<T>).tag || null !,
162-
template: (componentDefinition as ComponentDefArgs<T>).template || null !,
163-
r: componentDefinition.refresh || componentRefresh,
164-
inputs: invertObject(componentDefinition.inputs),
165-
outputs: invertObject(componentDefinition.outputs),
166-
methods: invertObject(componentDefinition.methods),
167-
rendererType: resolveRendererType2(componentDefinition.rendererType) || null,
168-
};
169-
const feature = componentDefinition.features;
170-
feature && feature.forEach((fn) => fn(def));
171-
return def;
172-
}
173-
174-
export function NgOnChangesFeature<T>(definition: DirectiveDef<T>) {
175-
// TODO: implement. See: https://app.asana.com/0/443577627818617/465170715764659
176-
}
177-
178-
export function PublicFeature<T>(definition: DirectiveDef<T>) {
179-
definition.diPublic = diPublic;
180-
}
181-
182-
const EMPTY = {};
183-
184-
/** Swaps the keys and values of an object. */
185-
function invertObject(obj: any): any {
186-
if (obj == null) return EMPTY;
187-
const newObj: any = {};
188-
for (let minifiedKey in obj) {
189-
newObj[obj[minifiedKey]] = minifiedKey;
190-
}
191-
return newObj;
192-
}
193-
194-
/**
195-
* Create a directive definition object.
196-
*
197-
* # Example
198-
* ```
199-
* class MyDirective {
200-
* // Generated by Angular Template Compiler
201-
* // [Symbol] syntax will not be supported by TypeScript until v2.7
202-
* static [DIRECTIVE_DEF_SYMBOL] = defineDirective({
203-
* ...
204-
* });
205-
* }
206-
* ```
207-
*/
208-
export const defineDirective = defineComponent as<T>(directiveDefinition: DirectiveDefArgs<T>) =>
209-
DirectiveDef<T>;

0 commit comments

Comments
 (0)