@@ -108,22 +108,18 @@ export class DirectiveResolver {
|
||||
var mergedQueries =
|
||||
isPresent(dm.queries) ? StringMapWrapper.merge(dm.queries, queries) : queries;
|
||||
|
||||
// TODO: remove after migrating from properties to inputs
|
||||
if (mergedInputs.length == 0 && isPresent(dm.properties)) mergedInputs = dm.properties;
|
||||
if (mergedOutputs.length == 0 && isPresent(dm.events)) mergedOutputs = dm.events;
|
||||
|
||||
if (dm instanceof ComponentMetadata) {
|
||||
return new ComponentMetadata({
|
||||
selector: dm.selector,
|
||||
inputs: mergedInputs,
|
||||
outputs: mergedOutputs,
|
||||
host: mergedHost,
|
||||
bindings: dm.bindings,
|
||||
exportAs: dm.exportAs,
|
||||
moduleId: dm.moduleId,
|
||||
queries: mergedQueries,
|
||||
changeDetection: dm.changeDetection,
|
||||
viewBindings: dm.viewBindings
|
||||
providers: dm.providers,
|
||||
viewProviders: dm.viewProviders
|
||||
});
|
||||
|
||||
} else {
|
||||
@@ -132,10 +128,10 @@ export class DirectiveResolver {
|
||||
inputs: mergedInputs,
|
||||
outputs: mergedOutputs,
|
||||
host: mergedHost,
|
||||
bindings: dm.bindings,
|
||||
exportAs: dm.exportAs,
|
||||
moduleId: dm.moduleId,
|
||||
queries: mergedQueries
|
||||
queries: mergedQueries,
|
||||
providers: dm.providers
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Key, Injector, ResolvedBinding, Binding, bind, Injectable} from 'angular2/src/core/di';
|
||||
import {Key, Injector, ResolvedProvider, Provider, provide, Injectable} from 'angular2/src/core/di';
|
||||
import {Compiler} from './compiler';
|
||||
import {isType, Type, stringify, isPresent} from 'angular2/src/core/facade/lang';
|
||||
import {Promise} from 'angular2/src/core/facade/async';
|
||||
@@ -161,7 +161,7 @@ export abstract class DynamicComponentLoader {
|
||||
* location within the Component View of this Component Instance is specified via `anchorName`
|
||||
* Template Variable Name.
|
||||
*
|
||||
* You can optionally provide `bindings` to configure the {@link Injector} provisioned for this
|
||||
* You can optionally provide `providers` to configure the {@link Injector} provisioned for this
|
||||
* Component Instance.
|
||||
*
|
||||
* Returns a promise for the {@link ComponentRef} representing the newly created Component.
|
||||
@@ -209,13 +209,13 @@ export abstract class DynamicComponentLoader {
|
||||
* ```
|
||||
*/
|
||||
abstract loadIntoLocation(type: Type, hostLocation: ElementRef, anchorName: string,
|
||||
bindings?: ResolvedBinding[]): Promise<ComponentRef>;
|
||||
providers?: ResolvedProvider[]): Promise<ComponentRef>;
|
||||
|
||||
/**
|
||||
* Creates an instance of a Component and attaches it to the View Container found at the
|
||||
* `location` specified as {@link ElementRef}.
|
||||
*
|
||||
* You can optionally provide `bindings` to configure the {@link Injector} provisioned for this
|
||||
* You can optionally provide `providers` to configure the {@link Injector} provisioned for this
|
||||
* Component Instance.
|
||||
*
|
||||
* Returns a promise for the {@link ComponentRef} representing the newly created Component.
|
||||
@@ -256,7 +256,7 @@ export abstract class DynamicComponentLoader {
|
||||
* <child-component>Child</child-component>
|
||||
* ```
|
||||
*/
|
||||
abstract loadNextToLocation(type: Type, location: ElementRef, bindings?: ResolvedBinding[]):
|
||||
abstract loadNextToLocation(type: Type, location: ElementRef, providers?: ResolvedProvider[]):
|
||||
Promise<ComponentRef>;
|
||||
}
|
||||
|
||||
@@ -283,17 +283,18 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
|
||||
}
|
||||
|
||||
loadIntoLocation(type: Type, hostLocation: ElementRef, anchorName: string,
|
||||
bindings: ResolvedBinding[] = null): Promise<ComponentRef> {
|
||||
providers: ResolvedProvider[] = null): Promise<ComponentRef> {
|
||||
return this.loadNextToLocation(
|
||||
type, this._viewManager.getNamedElementInComponentView(hostLocation, anchorName), bindings);
|
||||
type, this._viewManager.getNamedElementInComponentView(hostLocation, anchorName),
|
||||
providers);
|
||||
}
|
||||
|
||||
loadNextToLocation(type: Type, location: ElementRef,
|
||||
bindings: ResolvedBinding[] = null): Promise<ComponentRef> {
|
||||
providers: ResolvedProvider[] = null): Promise<ComponentRef> {
|
||||
return this._compiler.compileInHost(type).then(hostProtoViewRef => {
|
||||
var viewContainer = this._viewManager.getViewContainer(location);
|
||||
var hostViewRef =
|
||||
viewContainer.createHostView(hostProtoViewRef, viewContainer.length, bindings);
|
||||
viewContainer.createHostView(hostProtoViewRef, viewContainer.length, providers);
|
||||
var newLocation = this._viewManager.getHostElement(hostViewRef);
|
||||
var component = this._viewManager.getComponent(newLocation);
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {isBlank} from 'angular2/src/core/facade/lang';
|
||||
import {BaseException} from 'angular2/src/core/facade/exceptions';
|
||||
import * as eiModule from './element_injector';
|
||||
import {DirectiveBinding} from './element_injector';
|
||||
import {DirectiveProvider} from './element_injector';
|
||||
import * as viewModule from './view';
|
||||
|
||||
export class ElementBinder {
|
||||
constructor(public index: number, public parent: ElementBinder, public distanceToParent: number,
|
||||
public protoElementInjector: eiModule.ProtoElementInjector,
|
||||
public componentDirective: DirectiveBinding,
|
||||
public componentDirective: DirectiveProvider,
|
||||
public nestedProtoView: viewModule.AppProtoView) {
|
||||
if (isBlank(index)) {
|
||||
throw new BaseException('null index not allowed.');
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,14 +3,14 @@ import {isPresent, isBlank, Type, isArray, isNumber} from 'angular2/src/core/fac
|
||||
|
||||
import {RenderProtoViewRef} from 'angular2/src/core/render/api';
|
||||
|
||||
import {Injectable, Binding, resolveForwardRef, Inject} from 'angular2/src/core/di';
|
||||
import {Injectable, Provider, resolveForwardRef, Inject} from 'angular2/src/core/di';
|
||||
|
||||
import {PipeBinding} from '../pipes/pipe_binding';
|
||||
import {PipeProvider} from '../pipes/pipe_provider';
|
||||
import {ProtoPipes} from '../pipes/pipes';
|
||||
|
||||
import {AppProtoView, AppProtoViewMergeInfo, ViewType} from './view';
|
||||
import {ElementBinder} from './element_binder';
|
||||
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
|
||||
import {ProtoElementInjector, DirectiveProvider} from './element_injector';
|
||||
import {DirectiveResolver} from './directive_resolver';
|
||||
import {ViewResolver} from './view_resolver';
|
||||
import {PipeResolver} from './pipe_resolver';
|
||||
@@ -55,7 +55,7 @@ export class ProtoViewFactory {
|
||||
var result = this._cache.get(compiledTemplate.id);
|
||||
if (isBlank(result)) {
|
||||
var templateData = compiledTemplate.getData(this._appId);
|
||||
var emptyMap: {[key: string]: PipeBinding} = {};
|
||||
var emptyMap: {[key: string]: PipeProvider} = {};
|
||||
result = new AppProtoView(templateData.commands, ViewType.HOST, true,
|
||||
templateData.changeDetectorFactory, null, new ProtoPipes(emptyMap));
|
||||
this._cache.set(compiledTemplate.id, result);
|
||||
@@ -76,7 +76,7 @@ export class ProtoViewFactory {
|
||||
|
||||
nestedProtoView = new AppProtoView(compiledTemplateData.commands, ViewType.COMPONENT, true,
|
||||
compiledTemplateData.changeDetectorFactory, null,
|
||||
ProtoPipes.fromBindings(boundPipes));
|
||||
ProtoPipes.fromProviders(boundPipes));
|
||||
// Note: The cache is updated before recursing
|
||||
// to be able to resolve cycles
|
||||
this._cache.set(cmd.template.id, nestedProtoView);
|
||||
@@ -112,9 +112,9 @@ export class ProtoViewFactory {
|
||||
initializer.variableLocations);
|
||||
}
|
||||
|
||||
private _bindPipe(typeOrBinding): PipeBinding {
|
||||
let meta = this._pipeResolver.resolve(typeOrBinding);
|
||||
return PipeBinding.createFromType(typeOrBinding, meta);
|
||||
private _bindPipe(typeOrProvider): PipeProvider {
|
||||
let meta = this._pipeResolver.resolve(typeOrProvider);
|
||||
return PipeProvider.createFromType(typeOrProvider, meta);
|
||||
}
|
||||
|
||||
private _flattenPipes(view: ViewMetadata): any[] {
|
||||
@@ -245,12 +245,12 @@ function _createElementBinder(directiveResolver: DirectiveResolver, nestedProtoV
|
||||
if (isBlank(parentProtoElementInjector)) {
|
||||
distanceToParentPei = -1;
|
||||
}
|
||||
var componentDirectiveBinding: DirectiveBinding = null;
|
||||
var componentDirectiveProvider: DirectiveProvider = null;
|
||||
var isEmbeddedTemplate = false;
|
||||
var directiveBindings: DirectiveBinding[] =
|
||||
beginElementCmd.directives.map(type => bindDirective(directiveResolver, type));
|
||||
var directiveProviders: DirectiveProvider[] =
|
||||
beginElementCmd.directives.map(type => provideDirective(directiveResolver, type));
|
||||
if (beginElementCmd instanceof BeginComponentCmd) {
|
||||
componentDirectiveBinding = directiveBindings[0];
|
||||
componentDirectiveProvider = directiveProviders[0];
|
||||
} else if (beginElementCmd instanceof EmbeddedTemplateCmd) {
|
||||
isEmbeddedTemplate = true;
|
||||
}
|
||||
@@ -262,29 +262,29 @@ function _createElementBinder(directiveResolver: DirectiveResolver, nestedProtoV
|
||||
// so that, when hydrating, $implicit can be set to the element.
|
||||
// - <template> elements need their own ElementInjector so that we can query their TemplateRef
|
||||
var hasVariables = beginElementCmd.variableNameAndValues.length > 0;
|
||||
if (directiveBindings.length > 0 || hasVariables || isEmbeddedTemplate) {
|
||||
if (directiveProviders.length > 0 || hasVariables || isEmbeddedTemplate) {
|
||||
var directiveVariableBindings = new Map<string, number>();
|
||||
if (!isEmbeddedTemplate) {
|
||||
directiveVariableBindings =
|
||||
createDirectiveVariableBindings(beginElementCmd.variableNameAndValues, directiveBindings);
|
||||
directiveVariableBindings = createDirectiveVariableBindings(
|
||||
beginElementCmd.variableNameAndValues, directiveProviders);
|
||||
}
|
||||
protoElementInjector = ProtoElementInjector.create(
|
||||
parentProtoElementInjector, boundElementIndex, directiveBindings,
|
||||
isPresent(componentDirectiveBinding), distanceToParentPei, directiveVariableBindings);
|
||||
parentProtoElementInjector, boundElementIndex, directiveProviders,
|
||||
isPresent(componentDirectiveProvider), distanceToParentPei, directiveVariableBindings);
|
||||
protoElementInjector.attributes = arrayToMap(beginElementCmd.attrNameAndValues, false);
|
||||
}
|
||||
|
||||
return new ElementBinder(boundElementIndex, parentElementBinder, distanceToParentBinder,
|
||||
protoElementInjector, componentDirectiveBinding, nestedProtoView);
|
||||
protoElementInjector, componentDirectiveProvider, nestedProtoView);
|
||||
}
|
||||
|
||||
function bindDirective(directiveResolver: DirectiveResolver, type: Type): DirectiveBinding {
|
||||
function provideDirective(directiveResolver: DirectiveResolver, type: Type): DirectiveProvider {
|
||||
let annotation = directiveResolver.resolve(type);
|
||||
return DirectiveBinding.createFromType(type, annotation);
|
||||
return DirectiveProvider.createFromType(type, annotation);
|
||||
}
|
||||
|
||||
export function createDirectiveVariableBindings(variableNameAndValues: Array<string | number>,
|
||||
directiveBindings: DirectiveBinding[]):
|
||||
directiveProviders: DirectiveProvider[]):
|
||||
Map<string, number> {
|
||||
var directiveVariableBindings = new Map<string, number>();
|
||||
for (var i = 0; i < variableNameAndValues.length; i += 2) {
|
||||
@@ -313,7 +313,7 @@ function arrayToMap(arr: string[], inverse: boolean): Map<string, string> {
|
||||
return result;
|
||||
}
|
||||
|
||||
function _flattenList(tree: any[], out: Array<Type | Binding | any[]>): void {
|
||||
function _flattenList(tree: any[], out: Array<Type | Provider | any[]>): void {
|
||||
for (var i = 0; i < tree.length; i++) {
|
||||
var item = resolveForwardRef(tree[i]);
|
||||
if (isArray(item)) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
ProtoElementInjector,
|
||||
ElementInjector,
|
||||
PreBuiltObjects,
|
||||
DirectiveBinding
|
||||
DirectiveProvider
|
||||
} from './element_injector';
|
||||
import {ElementBinder} from './element_binder';
|
||||
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {unimplemented} from 'angular2/src/core/facade/exceptions';
|
||||
import {ResolvedBinding} from 'angular2/src/core/di';
|
||||
import {ResolvedProvider} from 'angular2/src/core/di';
|
||||
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
|
||||
|
||||
import * as avmModule from './view_manager';
|
||||
@@ -75,13 +75,13 @@ export abstract class ViewContainerRef {
|
||||
*
|
||||
* If `index` is not specified, the new View will be inserted as the last View in the container.
|
||||
*
|
||||
* You can optionally specify `dynamicallyCreatedBindings`, which configure the {@link Injector}
|
||||
* You can optionally specify `dynamicallyCreatedProviders`, which configure the {@link Injector}
|
||||
* that will be created for the Host View.
|
||||
*
|
||||
* Returns the {@link HostViewRef} of the Host View created for the newly instantiated Component.
|
||||
*/
|
||||
abstract createHostView(protoViewRef?: ProtoViewRef, index?: number,
|
||||
dynamicallyCreatedBindings?: ResolvedBinding[]): HostViewRef;
|
||||
dynamicallyCreatedProviders?: ResolvedProvider[]): HostViewRef;
|
||||
|
||||
/**
|
||||
* Inserts a View identified by a {@link ViewRef} into the container at the specified `index`.
|
||||
@@ -136,10 +136,10 @@ export class ViewContainerRef_ extends ViewContainerRef {
|
||||
}
|
||||
|
||||
createHostView(protoViewRef: ProtoViewRef = null, index: number = -1,
|
||||
dynamicallyCreatedBindings: ResolvedBinding[] = null): HostViewRef {
|
||||
dynamicallyCreatedProviders: ResolvedProvider[] = null): HostViewRef {
|
||||
if (index == -1) index = this.length;
|
||||
return this.viewManager.createHostViewInContainer(this.element, index, protoViewRef,
|
||||
dynamicallyCreatedBindings);
|
||||
dynamicallyCreatedProviders);
|
||||
}
|
||||
|
||||
// TODO(i): refactor insert+remove into move
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
Injector,
|
||||
Inject,
|
||||
Binding,
|
||||
Provider,
|
||||
Injectable,
|
||||
ResolvedBinding,
|
||||
ResolvedProvider,
|
||||
forwardRef
|
||||
} from 'angular2/src/core/di';
|
||||
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
|
||||
@@ -159,7 +159,7 @@ export abstract class AppViewManager {
|
||||
*/
|
||||
abstract createHostViewInContainer(viewContainerLocation: ElementRef, index: number,
|
||||
protoViewRef: ProtoViewRef,
|
||||
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef;
|
||||
imperativelyCreatedInjector: ResolvedProvider[]): HostViewRef;
|
||||
|
||||
/**
|
||||
* Destroys an Embedded or Host View attached to a View Container at the specified `index`.
|
||||
@@ -278,7 +278,7 @@ export class AppViewManager_ extends AppViewManager {
|
||||
|
||||
createHostViewInContainer(viewContainerLocation: ElementRef, index: number,
|
||||
protoViewRef: ProtoViewRef,
|
||||
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
|
||||
imperativelyCreatedInjector: ResolvedProvider[]): HostViewRef {
|
||||
var s = this._createHostViewInContainerScope();
|
||||
var protoView = internalProtoView(protoViewRef);
|
||||
if (protoView.type !== viewModule.ViewType.HOST) {
|
||||
@@ -297,7 +297,7 @@ export class AppViewManager_ extends AppViewManager {
|
||||
*/
|
||||
_createViewInContainer(viewContainerLocation: ElementRef, index: number,
|
||||
protoView: viewModule.AppProtoView, context: ElementRef,
|
||||
imperativelyCreatedInjector: ResolvedBinding[]): ViewRef {
|
||||
imperativelyCreatedInjector: ResolvedProvider[]): ViewRef {
|
||||
var parentView = internalView((<ElementRef_>viewContainerLocation).parentView);
|
||||
var boundElementIndex = (<ElementRef_>viewContainerLocation).boundElementIndex;
|
||||
var contextView = internalView((<ElementRef_>context).parentView);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Injector, Binding, Injectable, ResolvedBinding} from 'angular2/src/core/di';
|
||||
import {Injector, Provider, Injectable, ResolvedProvider} from 'angular2/src/core/di';
|
||||
import {ListWrapper, MapWrapper, Map, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||
import * as eli from './element_injector';
|
||||
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
|
||||
@@ -156,7 +156,7 @@ export class AppViewManagerUtils {
|
||||
|
||||
hydrateViewInContainer(parentView: viewModule.AppView, boundElementIndex: number,
|
||||
contextView: viewModule.AppView, contextBoundElementIndex: number,
|
||||
index: number, imperativelyCreatedBindings: ResolvedBinding[]) {
|
||||
index: number, imperativelyCreatedProviders: ResolvedProvider[]) {
|
||||
if (isBlank(contextView)) {
|
||||
contextView = parentView;
|
||||
contextBoundElementIndex = boundElementIndex;
|
||||
@@ -165,8 +165,8 @@ export class AppViewManagerUtils {
|
||||
var view = viewContainer.views[index];
|
||||
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
|
||||
|
||||
var injector = isPresent(imperativelyCreatedBindings) ?
|
||||
Injector.fromResolvedBindings(imperativelyCreatedBindings) :
|
||||
var injector = isPresent(imperativelyCreatedProviders) ?
|
||||
Injector.fromResolvedProviders(imperativelyCreatedProviders) :
|
||||
null;
|
||||
this._hydrateView(view, injector, elementInjector.getHost(), contextView.context,
|
||||
contextView.locals);
|
||||
|
||||
Reference in New Issue
Block a user