fix(di): hostInjector and viewInjector support nested arrays
This commit is contained in:
parent
b716046b97
commit
0ed5dd0d7b
|
@ -24,7 +24,6 @@ export * from './src/di/decorators';
|
|||
|
||||
export {forwardRef, resolveForwardRef, ForwardRefFn} from './src/di/forward_ref';
|
||||
export {
|
||||
resolveBindings,
|
||||
Injector,
|
||||
ProtoInjector,
|
||||
DependencyProvider,
|
||||
|
|
|
@ -25,7 +25,6 @@ import {
|
|||
AbstractBindingError,
|
||||
CyclicDependencyError,
|
||||
resolveForwardRef,
|
||||
resolveBindings,
|
||||
VisibilityMetadata,
|
||||
DependencyProvider,
|
||||
self
|
||||
|
@ -240,9 +239,9 @@ export class DirectiveBinding extends ResolvedBinding {
|
|||
var rb = binding.resolve();
|
||||
var deps = ListWrapper.map(rb.dependencies, DirectiveDependency.createFrom);
|
||||
var resolvedHostInjectables =
|
||||
isPresent(ann.hostInjector) ? resolveBindings(ann.hostInjector) : [];
|
||||
isPresent(ann.hostInjector) ? Injector.resolve(ann.hostInjector) : [];
|
||||
var resolvedViewInjectables = ann instanceof Component && isPresent(ann.viewInjector) ?
|
||||
resolveBindings(ann.viewInjector) :
|
||||
Injector.resolve(ann.viewInjector) :
|
||||
[];
|
||||
var metadata = DirectiveMetadata.create({
|
||||
id: stringify(rb.key.token),
|
||||
|
|
|
@ -364,7 +364,6 @@ function _createProtoElementInjector(binderIndex, parentPeiWithDistance, renderE
|
|||
if (directiveBindings.length > 0 || hasVariables) {
|
||||
var directiveVariableBindings =
|
||||
createDirectiveVariableBindings(renderElementBinder, directiveBindings);
|
||||
|
||||
protoElementInjector =
|
||||
ProtoElementInjector.create(parentPeiWithDistance.protoElementInjector, binderIndex,
|
||||
directiveBindings, isPresent(componentDirectiveBinding),
|
||||
|
|
|
@ -467,7 +467,7 @@ export class Injector {
|
|||
* `fromResolvedBindings` and `createChildFromResolved`.
|
||||
*/
|
||||
static resolve(bindings: List<Type | Binding | List<any>>): List<ResolvedBinding> {
|
||||
var resolvedBindings = resolveBindings(bindings);
|
||||
var resolvedBindings = _resolveBindings(bindings);
|
||||
var flatten = _flattenBindings(resolvedBindings, new Map());
|
||||
return _createListOfBindings(flatten);
|
||||
}
|
||||
|
@ -765,7 +765,7 @@ export class Injector {
|
|||
}
|
||||
|
||||
|
||||
export function resolveBindings(bindings: List<Type | Binding | List<any>>): List<ResolvedBinding> {
|
||||
function _resolveBindings(bindings: List<Type | Binding | List<any>>): List<ResolvedBinding> {
|
||||
var resolvedList = ListWrapper.createFixedSize(bindings.length);
|
||||
for (var i = 0; i < bindings.length; i++) {
|
||||
var unresolved = resolveForwardRef(bindings[i]);
|
||||
|
@ -777,7 +777,7 @@ export function resolveBindings(bindings: List<Type | Binding | List<any>>): Lis
|
|||
} else if (unresolved instanceof Binding) {
|
||||
resolved = unresolved.resolve();
|
||||
} else if (unresolved instanceof List) {
|
||||
resolved = resolveBindings(unresolved);
|
||||
resolved = _resolveBindings(unresolved);
|
||||
} else if (unresolved instanceof BindingBuilder) {
|
||||
throw new InvalidBindingError(unresolved.token);
|
||||
} else {
|
||||
|
|
|
@ -40,7 +40,7 @@ import {
|
|||
Directive,
|
||||
onDestroy
|
||||
} from 'angular2/annotations';
|
||||
import {bind, Injector, Binding, resolveBindings, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self, InjectMetadata, ParentMetadata} from 'angular2/di';
|
||||
import {bind, Injector, Binding, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self, InjectMetadata, ParentMetadata} from 'angular2/di';
|
||||
import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
|
||||
|
@ -486,6 +486,21 @@ export function main() {
|
|||
expect(pei.getBindingAtIndex(1).key.token).toEqual("injectable1");
|
||||
});
|
||||
|
||||
it("should collect view and host injectables from nested arrays", () => {
|
||||
var pei = createPei(null, 0, [
|
||||
DirectiveBinding.createFromType(
|
||||
SimpleDirective,
|
||||
new dirAnn.Component({
|
||||
viewInjector: [[[bind('view').toValue('view')]]],
|
||||
hostInjector: [[[bind('host').toValue('host')]]]
|
||||
}))
|
||||
], 0, true);
|
||||
|
||||
expect(pei.getBindingAtIndex(0).key.token).toBe(SimpleDirective);
|
||||
expect(pei.getBindingAtIndex(1).key.token).toEqual("view");
|
||||
expect(pei.getBindingAtIndex(2).key.token).toEqual("host");
|
||||
});
|
||||
|
||||
it('should support an arbitrary number of bindings', () => {
|
||||
var pei = createPei(null, 0, dynamicBindings);
|
||||
|
||||
|
|
|
@ -1697,12 +1697,12 @@ class DirectiveWithTwoWayBinding {
|
|||
class InjectableService {
|
||||
}
|
||||
|
||||
@Directive({selector: 'directive-providing-injectable', hostInjector: [InjectableService]})
|
||||
@Directive({selector: 'directive-providing-injectable', hostInjector: [[InjectableService]]})
|
||||
@Injectable()
|
||||
class DirectiveProvidingInjectable {
|
||||
}
|
||||
|
||||
@Component({selector: 'directive-providing-injectable', viewInjector: [InjectableService]})
|
||||
@Component({selector: 'directive-providing-injectable', viewInjector: [[InjectableService]]})
|
||||
@View({template: ''})
|
||||
@Injectable()
|
||||
class DirectiveProvidingInjectableInView {
|
||||
|
|
Loading…
Reference in New Issue