Skip to content
Closed

Ivy #20855

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8c2cbe
feat(core): Moving Renderer3 into @angular/core
mhevery Dec 1, 2017
e959440
refactor(core): store locals in main array in rederer3
mhevery Dec 8, 2017
8924445
perf: add large table and deep tree benchmarks for render3
marclaval Dec 11, 2017
e6b1ec7
perf: add benchmarks for IV and render3 with functions (tree)
marclaval Dec 12, 2017
f5af17c
docs(core): add comments to assert functions
kara Dec 13, 2017
d9826e5
docs(core): add comments to node_manipulation functions
kara Dec 13, 2017
b6c3101
refactor(core): store directive defs in static data
kara Dec 11, 2017
026748b
docs(core): document di and minor renames
kara Dec 13, 2017
4cf0d84
docs(core): add more comments to di and fix formatting
kara Dec 14, 2017
70c10c4
refactor(core): renamed and split out interfaces
kara Dec 14, 2017
cf65350
style: fix formatting errors
mhevery Dec 14, 2017
c7142c8
docs(core): add docs to instructions, minor renames
kara Dec 14, 2017
69db520
refactor(core): rename instructions for consistency
kara Dec 15, 2017
28cbf2f
perf: use style.setProperty instead of setAttribute in render3 and iv…
marclaval Dec 13, 2017
bc69f35
style: fix formatting errors
mhevery Dec 14, 2017
53e6363
feat: support queries for elements with local names
pkozlowski-opensource Dec 12, 2017
7618565
feat(core): add renderer factory in render3
marclaval Dec 11, 2017
48ad6e2
refactor: remove import circular dependencies
pkozlowski-opensource Dec 15, 2017
8be04bb
test(core): animation renderer factory in render3
marclaval Dec 15, 2017
c1d1f83
docs(core): add missing docs to component and fix formatting
kara Dec 15, 2017
0951ded
feat(core): support 'read' option for ngIvy queries
pkozlowski-opensource Dec 18, 2017
63a993f
build: yarn buildifier
mhevery Dec 19, 2017
58def09
build: fix benchmarks for render3
mhevery Dec 19, 2017
0ad6b71
build: fix circular dep between interface and l_node by merging
mhevery Dec 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
build: fix circular dep between interface and l_node by merging
  • Loading branch information
mhevery committed Dec 21, 2017
commit 0ad6b71cfd761a344e19c8693c7c8639898deee1
2 changes: 1 addition & 1 deletion modules/benchmarks/src/largetable/render3/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

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';
import {ComponentDef} from '@angular/core/src/render3/public_interfaces';
import {ComponentDef} from '@angular/core/src/render3/definition_interfaces';

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

Expand Down
2 changes: 1 addition & 1 deletion modules/benchmarks/src/tree/render3/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

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';
import {ComponentDef} from '@angular/core/src/render3/public_interfaces';
import {ComponentDef} from '@angular/core/src/render3/definition_interfaces';

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

Expand Down
16 changes: 9 additions & 7 deletions packages/core/src/render3/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

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

import {assertNotNull} from './assert';
import {ComponentDef, ComponentType} from './definition_interfaces';
import {NG_HOST_SYMBOL, createError, createViewState, directive, enterView, hostElement, leaveView, locateHostElement, renderComponentOrTemplate} from './instructions';
import {LElement} from './l_node';
import {ComponentDef, ComponentType} from './public_interfaces';
import {LElement} from './interfaces';
import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from './renderer';
import {notImplemented, stringify} from './util';

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

/** Module injector for the component. If unspecified, the injector will be NULL_INJECTOR. */
injector?: viewEngine.Injector;
injector?: Injector;

/**
* List of features to be applied to the created component. Features are simply
Expand All @@ -51,7 +53,7 @@ export interface CreateComponentOptions {
* @param options Optional parameters which control bootstrapping
*/
export function createComponentRef<T>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always for bootstrap? If so, would it make sense to say bootstrapComponent<T>? If not, createComponent?

This will better reflect what the function does rather than what it returns.

Copy link
Copy Markdown
Contributor

@jelbourn jelbourn Dec 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The analogy I'd make is that you want APIs to be like dialog.open(), not dialog.createDialogRef(), which, while accurate, is kind of missing the point

componentType: ComponentType<T>, opts: CreateComponentOptions): viewEngine.ComponentRef<T> {
componentType: ComponentType<T>, opts: CreateComponentOptions): viewEngine_ComponentRef<T> {
const component = renderComponent(componentType, opts);
const hostView = createViewRef(() => detectChanges(component), component);
return {
Expand All @@ -78,7 +80,7 @@ function createViewRef<T>(detectChanges: () => void, context: T): EmbeddedViewRe
return addDestroyable(new EmbeddedViewRef(detectChanges), context);
}

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


// TODO: A hack to not pull in the NullInjector from @angular/core.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you fix the hack before landing in master?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it would break the other repo, will fix when we officially cut over

export const NULL_INJECTOR: viewEngine.Injector = {
export const NULL_INJECTOR: Injector = {
get: (token: any, notFoundValue?: any) => {
throw new Error('NullInjector: Not found: ' + stringify(token));
}
Expand Down
87 changes: 87 additions & 0 deletions packages/core/src/render3/definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @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 {RendererType2} from '../render/api';
import {Type} from '../type';
import {resolveRendererType2} from '../view/util';

import {ComponentDef, ComponentDefArgs, DirectiveDef, DirectiveDefArgs} from './definition_interfaces';
import {componentRefresh, diPublic} from './instructions';



/**
* Create a component definition object.
*
*
* # Example
* ```
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static [COMPONENT_DEF_SYMBOL] = defineComponent({
* ...
* });
* }
* ```
*/
export function defineComponent<T>(componentDefinition: ComponentDefArgs<T>): ComponentDef<T> {
const def = <ComponentDef<any>>{
type: componentDefinition.type,
diPublic: null,
n: componentDefinition.factory,
tag: (componentDefinition as ComponentDefArgs<T>).tag || null !,
template: (componentDefinition as ComponentDefArgs<T>).template || null !,
r: componentDefinition.refresh ||
function(d: number, e: number) { componentRefresh(d, e, componentDefinition.template); },
inputs: invertObject(componentDefinition.inputs),
outputs: invertObject(componentDefinition.outputs),
methods: invertObject(componentDefinition.methods),
rendererType: resolveRendererType2(componentDefinition.rendererType) || null,
};
const feature = componentDefinition.features;
feature && feature.forEach((fn) => fn(def));
return def;
}

export function NgOnChangesFeature<T>(definition: DirectiveDef<T>) {
// TODO: implement. See: https://app.asana.com/0/443577627818617/465170715764659
}

export function PublicFeature<T>(definition: DirectiveDef<T>) {
definition.diPublic = diPublic;
}

const EMPTY = {};

/** Swaps the keys and values of an object. */
function invertObject(obj: any): any {
if (obj == null) return EMPTY;
const newObj: any = {};
for (let minifiedKey in obj) {
newObj[obj[minifiedKey]] = minifiedKey;
}
return newObj;
}

/**
* Create a directive definition object.
*
* # Example
* ```
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static [DIRECTIVE_DEF_SYMBOL] = defineDirective({
* ...
* });
* }
* ```
*/
export const defineDirective = defineComponent as<T>(directiveDefinition: DirectiveDefArgs<T>) =>
DirectiveDef<T>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/

import {RendererType2, Type} from '../core';
import {RendererType2} from '../render/api';
import {Type} from '../type';
import {resolveRendererType2} from '../view/util';
import {componentRefresh, diPublic} from './instructions';



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

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

/**
* The tag name which should be used by the component.
Expand All @@ -120,7 +120,7 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
export interface DirectiveDefArgs<T> {
type: Type<T>;
factory: () => T;
refresh?: (this: DirectiveDef<T>, directiveIndex: number, elementIndex: number) => void;
refresh?: (directiveIndex: number, elementIndex: number) => void;
inputs?: {[P in keyof T]?: string};
outputs?: {[P in keyof T]?: string};
methods?: {[P in keyof T]?: string};
Expand All @@ -130,80 +130,10 @@ export interface DirectiveDefArgs<T> {
export interface ComponentDefArgs<T> extends DirectiveDefArgs<T> {
tag: string;
template: ComponentTemplate<T>;
refresh?: (this: ComponentDef<T>, directiveIndex: number, elementIndex: number) => void;
refresh?: (directiveIndex: number, elementIndex: number) => void;
features?: ComponentDefFeature[];
rendererType?: RendererType2;
}

export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;

/**
* Create a component definition object.
*
*
* # Example
* ```
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static [COMPONENT_DEF_SYMBOL] = defineComponent({
* ...
* });
* }
* ```
*/
export function defineComponent<T>(componentDefinition: ComponentDefArgs<T>): ComponentDef<T> {
const def = <ComponentDef<any>>{
type: componentDefinition.type,
diPublic: null,
n: componentDefinition.factory,
tag: (componentDefinition as ComponentDefArgs<T>).tag || null !,
template: (componentDefinition as ComponentDefArgs<T>).template || null !,
r: componentDefinition.refresh || componentRefresh,
inputs: invertObject(componentDefinition.inputs),
outputs: invertObject(componentDefinition.outputs),
methods: invertObject(componentDefinition.methods),
rendererType: resolveRendererType2(componentDefinition.rendererType) || null,
};
const feature = componentDefinition.features;
feature && feature.forEach((fn) => fn(def));
return def;
}

export function NgOnChangesFeature<T>(definition: DirectiveDef<T>) {
// TODO: implement. See: https://app.asana.com/0/443577627818617/465170715764659
}

export function PublicFeature<T>(definition: DirectiveDef<T>) {
definition.diPublic = diPublic;
}

const EMPTY = {};

/** Swaps the keys and values of an object. */
function invertObject(obj: any): any {
if (obj == null) return EMPTY;
const newObj: any = {};
for (let minifiedKey in obj) {
newObj[obj[minifiedKey]] = minifiedKey;
}
return newObj;
}

/**
* Create a directive definition object.
*
* # Example
* ```
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static [DIRECTIVE_DEF_SYMBOL] = defineDirective({
* ...
* });
* }
* ```
*/
export const defineDirective = defineComponent as<T>(directiveDefinition: DirectiveDefArgs<T>) =>
DirectiveDef<T>;
Loading