refactor(view): remove hostActions

BREAKING CHANGE

Closes #3396

Replacement. Either direct DOM access or Renderer in WebWorkers.
This commit is contained in:
Misko Hevery
2015-08-26 13:55:53 -07:00
parent 37b042b361
commit ac3f5106e4
14 changed files with 13 additions and 185 deletions

View File

@ -117,11 +117,6 @@ class HasEventEmitter {
constructor() { this.emitter = "emitter"; }
}
class HasHostAction {
hostActionName;
constructor() { this.hostActionName = "hostAction"; }
}
class NeedsAttribute {
typeAttribute;
titleAttribute;
@ -433,18 +428,6 @@ export function main() {
expect(accessor.eventName).toEqual('publicEmitter');
expect(accessor.getter(new HasEventEmitter())).toEqual('emitter');
});
it('should return a list of hostAction accessors', () => {
var binding = DirectiveBinding.createFromType(
HasEventEmitter, new DirectiveMetadata({host: {'@hostActionName': 'onAction'}}));
var inj = createPei(null, 0, [binding]);
expect(inj.hostActionAccessors.length).toEqual(1);
var accessor = inj.hostActionAccessors[0][0];
expect(accessor.methodName).toEqual('onAction');
expect(accessor.getter(new HasHostAction())).toEqual('hostAction');
});
});
describe(".create", () => {

View File

@ -841,31 +841,6 @@ export function main() {
});
}));
if (DOM.supportsDOMEvents()) {
it("should support invoking methods on the host element via hostActions",
inject(
[TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<div update-host-actions></div>',
directives: [DirectiveUpdatingHostActions]
}))
.createAsync(MyComp)
.then((rootTC) => {
var tc = rootTC.componentViewChildren[0];
var nativeElement = tc.nativeElement;
var updateHost = tc.inject(DirectiveUpdatingHostActions);
ObservableWrapper.subscribe(updateHost.setAttr, (_) => {
expect(DOM.hasAttribute(nativeElement, 'update-host-actions')).toBe(true);
async.done();
});
updateHost.triggerSetAttr('value');
});
}));
}
it('should support render events',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(

View File

@ -87,17 +87,13 @@ export function main() {
createHostPv([createNestedElBinder(createComponentPv()), createEmptyElBinder()]);
var hostView = createViewWithChildren(hostPv);
var spyEventAccessor1 = SpyObject.stub({"subscribe": null});
SpyObject.stub(hostView.elementInjectors[0], {
'getHostActionAccessors': [],
'getEventEmitterAccessors': [[spyEventAccessor1]],
'getDirectiveAtIndex': dir
});
SpyObject.stub(
hostView.elementInjectors[0],
{'getEventEmitterAccessors': [[spyEventAccessor1]], 'getDirectiveAtIndex': dir});
var spyEventAccessor2 = SpyObject.stub({"subscribe": null});
SpyObject.stub(hostView.elementInjectors[1], {
'getHostActionAccessors': [],
'getEventEmitterAccessors': [[spyEventAccessor2]],
'getDirectiveAtIndex': dir
});
SpyObject.stub(
hostView.elementInjectors[1],
{'getEventEmitterAccessors': [[spyEventAccessor2]], 'getDirectiveAtIndex': dir});
utils.hydrateRootHostView(hostView, createInjector());
@ -105,31 +101,6 @@ export function main() {
expect(spyEventAccessor2.spy('subscribe')).toHaveBeenCalledWith(hostView, 1, dir);
});
it("should set up host action listeners", () => {
var dir = new Object();
var hostPv =
createHostPv([createNestedElBinder(createComponentPv()), createEmptyElBinder()]);
var hostView = createViewWithChildren(hostPv);
var spyActionAccessor1 = SpyObject.stub({"subscribe": null});
SpyObject.stub(hostView.elementInjectors[0], {
'getHostActionAccessors': [[spyActionAccessor1]],
'getEventEmitterAccessors': [],
'getDirectiveAtIndex': dir
});
var spyActionAccessor2 = SpyObject.stub({"subscribe": null});
SpyObject.stub(hostView.elementInjectors[1], {
'getHostActionAccessors': [[spyActionAccessor2]],
'getEventEmitterAccessors': [],
'getDirectiveAtIndex': dir
});
utils.hydrateRootHostView(hostView, createInjector());
expect(spyActionAccessor1.spy('subscribe')).toHaveBeenCalledWith(hostView, 0, dir);
expect(spyActionAccessor2.spy('subscribe')).toHaveBeenCalledWith(hostView, 1, dir);
});
it("should not hydrate element injectors of component views inside of embedded fragments",
() => {
var hostView = createViewWithChildren(createHostPv([

View File

@ -8,17 +8,12 @@ export function main() {
describe('host', () => {
it('should parse host configuration', () => {
var md = RenderDirectiveMetadata.create({
host: MapWrapper.createFromPairs([
['(event)', 'eventVal'],
['[prop]', 'propVal'],
['@action', 'actionVal'],
['attr', 'attrVal']
])
host: MapWrapper.createFromPairs(
[['(event)', 'eventVal'], ['[prop]', 'propVal'], ['attr', 'attrVal']])
});
expect(md.hostListeners).toEqual(MapWrapper.createFromPairs([['event', 'eventVal']]));
expect(md.hostProperties).toEqual(MapWrapper.createFromPairs([['prop', 'propVal']]));
expect(md.hostActions).toEqual(MapWrapper.createFromPairs([['action', 'actionVal']]));
expect(md.hostAttributes).toEqual(MapWrapper.createFromPairs([['attr', 'attrVal']]));
});
});