fix(element_injector): changed visibility rules to expose hostInjector of the component to its shadow dom

This commit is contained in:
vsavkin
2015-06-11 13:54:17 -07:00
parent bbfb4e1dcc
commit c51aef9f7d
3 changed files with 47 additions and 51 deletions

View File

@ -625,15 +625,38 @@ export function main() {
expect(inj.get(NeedsService).service).toEqual('service');
});
it("should prioritize hostInjector over viewInjector for the same binding", () => {
it("should prioritize viewInjector over hostInjector for the same binding", () => {
var inj = injector(
ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new dirAnn.Component({
hostInjector: [bind('service').toValue('hostService')],
viewInjector: [bind('service').toValue('viewService')]})
)], extraBindings), null, true);
expect(inj.get(NeedsService).service).toEqual('hostService');
expect(inj.get(NeedsService).service).toEqual('viewService');
});
it("should instantiate a directive in a view that depends on hostInjector bindings of the component", () => {
var shadowInj = hostShadowInjectors(
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
hostInjector: [bind('service').toValue('hostService')]})
)], extraBindings),
ListWrapper.concat([NeedsService], extraBindings)
);
expect(shadowInj.get(NeedsService).service).toEqual('hostService');
});
it("should not instantiate a directive in a view that depends on hostInjector bindings of a decorator directive", () => {
expect(() => {
hostShadowInjectors(
ListWrapper.concat([
SimpleDirective,
DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Directive({
hostInjector: [bind('service').toValue('hostService')]})
)], extraBindings),
ListWrapper.concat([NeedsService], extraBindings)
);
}).toThrowError(new RegExp("No provider for service!"));
});
it("should instantiate directives that depend on app services", () => {
var appInjector = Injector.resolveAndCreate(

View File

@ -973,28 +973,6 @@ export function main() {
});
}));
it('should prioritze hostInjector over viewInjector for the same binding',
inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => {
tb.overrideView(MyComp, new viewAnn.View({
template: `
<directive-providing-injectable>
<directive-consuming-injectable #consuming>
</directive-consuming-injectable>
</directive-providing-injectable>
`,
directives:
[DirectiveProvidingInjectableInHostAndView, DirectiveConsumingInjectable]
}));
tb.createView(MyComp, {context: ctx})
.then((view) => {
var comp = view.rawView.locals.get("consuming");
expect(comp.injectable).toEqual("host");
async.done();
});
}));
it("should support viewInjector",
inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => {
tb.overrideView(DirectiveProvidingInjectableInView, new viewAnn.View({
@ -1688,23 +1666,15 @@ class GrandParentProvidingEventBus {
constructor(bus: EventBus) { this.bus = bus; }
}
function createParentBusHost(peb) {
function createParentBus(peb) {
return new EventBus(peb, "parent");
}
function createParentBusView(p) {
return p.bus;
}
@Component({
selector: 'parent-providing-event-bus',
hostInjector: [
new Binding(EventBus,
{toFactory: createParentBusHost, deps: [[EventBus, new visAnn.Unbounded()]]})
],
viewInjector: [
new Binding(
EventBus,
{toFactory: createParentBusView, deps: [[forwardRef(() => ParentProvidingEventBus)]]})
{toFactory: createParentBus, deps: [[EventBus, new visAnn.Unbounded()]]})
]
})
@View({
@ -1718,7 +1688,6 @@ class ParentProvidingEventBus {
grandParentBus: EventBus;
constructor(bus: EventBus, @Unbounded() grandParentBus: EventBus) {
// constructor(bus: EventBus) {
this.bus = bus;
this.grandParentBus = grandParentBus;
}