feat(di): removed publishAs
BREAKING CHANGES Removes the publishAs property from the Component annotation.
This commit is contained in:
@ -195,30 +195,6 @@ class TestNode extends TreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
// TypeScript erases interfaces, so it has to be a class
|
||||
class ParentInterface {}
|
||||
|
||||
class ParentComponent extends ParentInterface {
|
||||
}
|
||||
|
||||
class AppDependency {
|
||||
parent:ParentInterface;
|
||||
|
||||
constructor(p:ParentInterface) {
|
||||
this.parent = p;
|
||||
}
|
||||
}
|
||||
|
||||
class ChildComponent {
|
||||
parent:ParentInterface;
|
||||
appDependency:AppDependency;
|
||||
|
||||
constructor(p:ParentInterface, a:AppDependency) {
|
||||
this.parent = p;
|
||||
this.appDependency = a;
|
||||
}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
var defaultPreBuiltObjects = new PreBuiltObjects(null, null, null);
|
||||
var appInjector = Injector.resolveAndCreate([]);
|
||||
@ -647,31 +623,6 @@ export function main() {
|
||||
inj.clearDirectives();
|
||||
expect(destroy.onDestroyCounter).toBe(1);
|
||||
});
|
||||
|
||||
it("should publish component to its children via app injector when requested", function() {
|
||||
var parentDirective = new Component({
|
||||
selector: 'parent',
|
||||
publishAs: [ParentInterface]
|
||||
});
|
||||
var parentBinding = DirectiveBinding.createFromType(ParentComponent, parentDirective);
|
||||
|
||||
var childDirective = new Component({
|
||||
selector: 'child',
|
||||
injectables: [AppDependency]
|
||||
});
|
||||
var childBinding = DirectiveBinding.createFromType(ChildComponent, childDirective);
|
||||
|
||||
var child = hostShadowInjectors([parentBinding], [childBinding], true, true);
|
||||
var d = child.get(ChildComponent);
|
||||
|
||||
// Verify that the child component can inject parent via interface binding
|
||||
expect(d).toBeAnInstanceOf(ChildComponent);
|
||||
expect(d.parent).toBeAnInstanceOf(ParentComponent);
|
||||
|
||||
// Verify that the binding is available down the dependency tree
|
||||
expect(d.appDependency.parent).toBeAnInstanceOf(ParentComponent);
|
||||
expect(d.parent).toBe(d.appDependency.parent);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dynamicallyCreateComponent", () => {
|
||||
|
@ -986,71 +986,6 @@ export function main() {
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
describe('dependency injection', () => {
|
||||
|
||||
it('should publish parent component to shadow DOM via publishAs',
|
||||
inject([TestBed, AsyncTestCompleter, Compiler], (tb, async, compiler) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
template: `<parent></parent>`,
|
||||
directives: [ParentComponent]
|
||||
}));
|
||||
|
||||
tb.createView(MyComp).then((view) => {
|
||||
view.detectChanges();
|
||||
expect(view.rootNodes).toHaveText(
|
||||
'Parent,Parent');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should override parent bindings via publishAs',
|
||||
inject([TestBed, AsyncTestCompleter, Compiler], (tb, async, compiler) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
template: `<recursive-parent></recursive-parent>`,
|
||||
directives: [RecursiveParentComponent]
|
||||
}));
|
||||
|
||||
tb.createView(MyComp).then((view) => {
|
||||
view.detectChanges();
|
||||
expect(view.rootNodes).toHaveText(
|
||||
'ParentInterface,RecursiveParent,RecursiveParent');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
// [DynamicComponentLoader] already supports providing a custom
|
||||
// injector as an argument to `loadIntoExistingLocation`, which should
|
||||
// be used instead of `publishAs`.
|
||||
//
|
||||
// Conceptually dynamically loaded components are loaded _instead_ of
|
||||
// the dynamic component itself. The dynamic component does not own the
|
||||
// shadow DOM. It's the loaded component that creates that shadow DOM.
|
||||
it('should not publish into dynamically instantiated components via publishAs',
|
||||
inject([TestBed, AsyncTestCompleter, Compiler], (tb, async, compiler) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
template: `<dynamic-parent #cmp></dynamic-parent>`,
|
||||
directives: [DynamicParentComponent]
|
||||
}));
|
||||
|
||||
tb.createView(MyComp).then((view) => {
|
||||
view.detectChanges();
|
||||
var comp = view.rawView.locals.get("cmp");
|
||||
PromiseWrapper.then(comp.done,
|
||||
(value) => {
|
||||
throw new BaseException(`Expected to throw error, but got value ${value}`);
|
||||
},
|
||||
(err) => {
|
||||
expect(err.message)
|
||||
.toEqual('No provider for ParentInterface! (ChildComponent -> ParentInterface)');
|
||||
async.done();
|
||||
}
|
||||
);
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -1479,70 +1414,6 @@ class NeedsPublicApi {
|
||||
}
|
||||
}
|
||||
|
||||
class ParentInterface {
|
||||
message:String;
|
||||
constructor() {
|
||||
this.message = 'ParentInterface';
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'parent',
|
||||
publishAs: [ParentInterface]
|
||||
})
|
||||
@View({
|
||||
template: `<child></child>`,
|
||||
directives: [ChildComponent]
|
||||
})
|
||||
class ParentComponent extends ParentInterface {
|
||||
message:String;
|
||||
constructor() {
|
||||
super();
|
||||
this.message = 'Parent';
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
injectables: [ParentInterface],
|
||||
selector: 'recursive-parent',
|
||||
publishAs: [ParentInterface]
|
||||
})
|
||||
@View({
|
||||
template: `{{parentService.message}},<child></child>`,
|
||||
directives: [ChildComponent]
|
||||
})
|
||||
class RecursiveParentComponent extends ParentInterface {
|
||||
parentService:ParentInterface;
|
||||
message:String;
|
||||
constructor(parentService:ParentInterface) {
|
||||
super();
|
||||
this.message = 'RecursiveParent';
|
||||
this.parentService = parentService;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'dynamic-parent',
|
||||
publishAs: [ParentInterface]
|
||||
})
|
||||
class DynamicParentComponent extends ParentInterface {
|
||||
message:String;
|
||||
done;
|
||||
constructor(loader:DynamicComponentLoader, location:ElementRef) {
|
||||
super();
|
||||
this.message = 'DynamicParent';
|
||||
this.done = loader.loadIntoExistingLocation(ChildComponent, location);
|
||||
}
|
||||
}
|
||||
|
||||
class AppDependency {
|
||||
parent:ParentInterface;
|
||||
|
||||
constructor(p:ParentInterface) {
|
||||
this.parent = p;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'child',
|
||||
injectables: [AppDependency]
|
||||
|
Reference in New Issue
Block a user