Skip to content

Commit ac3f510

Browse files
committed
refactor(view): remove hostActions
BREAKING CHANGE Closes angular#3396 Replacement. Either direct DOM access or Renderer in WebWorkers.
1 parent 37b042b commit ac3f510

File tree

14 files changed

+13
-185
lines changed

14 files changed

+13
-185
lines changed

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,6 @@ export class DirectiveBinding extends ResolvedBinding {
214214
return isPresent(this.metadata) && isPresent(this.metadata.events) ? this.metadata.events : [];
215215
}
216216

217-
get hostActions(): Map<string, string> {
218-
return isPresent(this.metadata) && isPresent(this.metadata.hostActions) ?
219-
this.metadata.hostActions :
220-
new Map();
221-
}
222-
223217
get changeDetection() { return this.metadata.changeDetection; }
224218

225219
static createFromBinding(binding: Binding, ann: DirectiveMetadata): DirectiveBinding {
@@ -312,22 +306,10 @@ function _createEventEmitterAccessors(bwv: BindingWithVisibility): EventEmitterA
312306
});
313307
}
314308

315-
function _createHostActionAccessors(bwv: BindingWithVisibility): HostActionAccessor[] {
316-
var binding = bwv.binding;
317-
if (!(binding instanceof DirectiveBinding)) return [];
318-
var res = [];
319-
var db = <DirectiveBinding>binding;
320-
MapWrapper.forEach(db.hostActions, (actionExpression, actionName) => {
321-
res.push(new HostActionAccessor(actionExpression, reflector.getter(actionName)));
322-
});
323-
return res;
324-
}
325-
326309
export class ProtoElementInjector {
327310
view: viewModule.AppView;
328311
attributes: Map<string, string>;
329312
eventEmitterAccessors: List<List<EventEmitterAccessor>>;
330-
hostActionAccessors: List<List<HostActionAccessor>>;
331313
protoInjector: ProtoInjector;
332314

333315
static create(parent: ProtoElementInjector, index: number, bindings: List<ResolvedBinding>,
@@ -386,15 +368,10 @@ export class ProtoElementInjector {
386368
public _firstBindingIsComponent: boolean,
387369
public directiveVariableBindings: Map<string, number>) {
388370
var length = bwv.length;
389-
390371
this.protoInjector = new ProtoInjector(bwv);
391-
392372
this.eventEmitterAccessors = ListWrapper.createFixedSize(length);
393-
this.hostActionAccessors = ListWrapper.createFixedSize(length);
394-
395373
for (var i = 0; i < length; ++i) {
396374
this.eventEmitterAccessors[i] = _createEventEmitterAccessors(bwv[i]);
397-
this.hostActionAccessors[i] = _createHostActionAccessors(bwv[i]);
398375
}
399376
}
400377

@@ -563,10 +540,6 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
563540
return this._proto.eventEmitterAccessors;
564541
}
565542

566-
getHostActionAccessors(): List<List<HostActionAccessor>> {
567-
return this._proto.hostActionAccessors;
568-
}
569-
570543
getDirectiveVariableBindings(): Map<string, number> {
571544
return this._proto.directiveVariableBindings;
572545
}

modules/angular2/src/core/compiler/view_manager_utils.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ export class AppViewManagerUtils {
211211
currView.preBuiltObjects[boundElementIndex]);
212212
this._populateViewLocals(currView, elementInjector, boundElementIndex);
213213
this._setUpEventEmitters(currView, elementInjector, boundElementIndex);
214-
this._setUpHostActions(currView, elementInjector, boundElementIndex);
215214
}
216215
}
217216
var pipes = isPresent(hostElementInjector) ?
@@ -250,20 +249,6 @@ export class AppViewManagerUtils {
250249
}
251250
}
252251

253-
_setUpHostActions(view: viewModule.AppView, elementInjector: eli.ElementInjector,
254-
boundElementIndex: number) {
255-
var hostActions = elementInjector.getHostActionAccessors();
256-
for (var directiveIndex = 0; directiveIndex < hostActions.length; ++directiveIndex) {
257-
var directiveHostActions = hostActions[directiveIndex];
258-
var directive = elementInjector.getDirectiveAtIndex(directiveIndex);
259-
260-
for (var index = 0; index < directiveHostActions.length; ++index) {
261-
var hostActionAccessor = directiveHostActions[index];
262-
hostActionAccessor.subscribe(view, boundElementIndex, directive);
263-
}
264-
}
265-
}
266-
267252
dehydrateView(initView: viewModule.AppView) {
268253
var endViewOffset = initView.viewOffset +
269254
initView.mainMergeMapping.nestedViewCountByViewIndex[initView.viewOffset];

modules/angular2/src/core/metadata/directives.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -628,31 +628,6 @@ export class DirectiveMetadata extends InjectableMetadata {
628628
* In this example using `my-button` directive (ex.: `<div my-button></div>`) on a host element
629629
* (here: `<div>` ) will ensure that this element will get the "button" role.
630630
*
631-
* ## Actions
632-
*
633-
* Specifies which DOM methods a directive can invoke.
634-
*
635-
* ## Syntax
636-
*
637-
* ```
638-
* @Directive({
639-
* selector: 'input',
640-
* host: {
641-
* '@emitFocus': 'focus()'
642-
* }
643-
* })
644-
* class InputDirective {
645-
* constructor() {
646-
* this.emitFocus = new EventEmitter();
647-
* }
648-
*
649-
* focus() {
650-
* this.emitFocus.next();
651-
* }
652-
* }
653-
* ```
654-
*
655-
* In this example calling focus on InputDirective will result in calling focus on the input.
656631
*/
657632
host: StringMap<string, string>;
658633

modules/angular2/src/core/render/api.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,20 @@ export class RenderDirectiveMetadata {
163163
hostListeners: Map<string, string>;
164164
hostProperties: Map<string, string>;
165165
hostAttributes: Map<string, string>;
166-
hostActions: Map<string, string>;
167166
// group 1: "property" from "[property]"
168167
// group 2: "event" from "(event)"
169-
// group 3: "action" from "@action"
170-
private static _hostRegExp = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\))|(?:@(.+)))$/g;
168+
private static _hostRegExp = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
171169

172170
constructor({id, selector, compileChildren, events, hostListeners, hostProperties, hostAttributes,
173-
hostActions, properties, readAttributes, type, callOnDestroy, callOnChange,
174-
callOnCheck, callOnInit, callOnAllChangesDone, changeDetection, exportAs}: {
171+
properties, readAttributes, type, callOnDestroy, callOnChange, callOnCheck,
172+
callOnInit, callOnAllChangesDone, changeDetection, exportAs}: {
175173
id?: string,
176174
selector?: string,
177175
compileChildren?: boolean,
178176
events?: List<string>,
179177
hostListeners?: Map<string, string>,
180178
hostProperties?: Map<string, string>,
181179
hostAttributes?: Map<string, string>,
182-
hostActions?: Map<string, string>,
183180
properties?: List<string>,
184181
readAttributes?: List<string>,
185182
type?: number,
@@ -198,7 +195,6 @@ export class RenderDirectiveMetadata {
198195
this.hostListeners = hostListeners;
199196
this.hostAttributes = hostAttributes;
200197
this.hostProperties = hostProperties;
201-
this.hostActions = hostActions;
202198
this.properties = properties;
203199
this.readAttributes = readAttributes;
204200
this.type = type;
@@ -233,7 +229,6 @@ export class RenderDirectiveMetadata {
233229
let hostListeners = new Map();
234230
let hostProperties = new Map();
235231
let hostAttributes = new Map();
236-
let hostActions = new Map();
237232

238233
if (isPresent(host)) {
239234
MapWrapper.forEach(host, (value: string, key: string) => {
@@ -244,8 +239,6 @@ export class RenderDirectiveMetadata {
244239
hostProperties.set(matches[1], value);
245240
} else if (isPresent(matches[2])) {
246241
hostListeners.set(matches[2], value);
247-
} else if (isPresent(matches[3])) {
248-
hostActions.set(matches[3], value);
249242
}
250243
});
251244
}
@@ -258,7 +251,6 @@ export class RenderDirectiveMetadata {
258251
hostListeners: hostListeners,
259252
hostProperties: hostProperties,
260253
hostAttributes: hostAttributes,
261-
hostActions: hostActions,
262254
properties: properties,
263255
readAttributes: readAttributes,
264256
type: type,

modules/angular2/src/web_workers/shared/serializer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ export class Serializer {
380380
'exportAs': meta.exportAs,
381381
'hostProperties': this.mapToObject(meta.hostProperties),
382382
'hostListeners': this.mapToObject(meta.hostListeners),
383-
'hostActions': this.mapToObject(meta.hostActions),
384383
'hostAttributes': this.mapToObject(meta.hostAttributes)
385384
};
386385
return obj;
@@ -392,7 +391,6 @@ export class Serializer {
392391
compileChildren: obj['compileChildren'],
393392
hostProperties: this.objectToMap(obj['hostProperties']),
394393
hostListeners: this.objectToMap(obj['hostListeners']),
395-
hostActions: this.objectToMap(obj['hostActions']),
396394
hostAttributes: this.objectToMap(obj['hostAttributes']),
397395
properties: obj['properties'],
398396
readAttributes: obj['readAttributes'],

modules/angular2/test/core/compiler/element_injector_spec.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ class HasEventEmitter {
117117
constructor() { this.emitter = "emitter"; }
118118
}
119119

120-
class HasHostAction {
121-
hostActionName;
122-
constructor() { this.hostActionName = "hostAction"; }
123-
}
124-
125120
class NeedsAttribute {
126121
typeAttribute;
127122
titleAttribute;
@@ -433,18 +428,6 @@ export function main() {
433428
expect(accessor.eventName).toEqual('publicEmitter');
434429
expect(accessor.getter(new HasEventEmitter())).toEqual('emitter');
435430
});
436-
437-
it('should return a list of hostAction accessors', () => {
438-
var binding = DirectiveBinding.createFromType(
439-
HasEventEmitter, new DirectiveMetadata({host: {'@hostActionName': 'onAction'}}));
440-
441-
var inj = createPei(null, 0, [binding]);
442-
expect(inj.hostActionAccessors.length).toEqual(1);
443-
444-
var accessor = inj.hostActionAccessors[0][0];
445-
expect(accessor.methodName).toEqual('onAction');
446-
expect(accessor.getter(new HasHostAction())).toEqual('hostAction');
447-
});
448431
});
449432

450433
describe(".create", () => {

modules/angular2/test/core/compiler/integration_spec.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -841,31 +841,6 @@ export function main() {
841841
});
842842
}));
843843

844-
if (DOM.supportsDOMEvents()) {
845-
it("should support invoking methods on the host element via hostActions",
846-
inject(
847-
[TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
848-
tcb.overrideView(MyComp, new ViewMetadata({
849-
template: '<div update-host-actions></div>',
850-
directives: [DirectiveUpdatingHostActions]
851-
}))
852-
853-
.createAsync(MyComp)
854-
.then((rootTC) => {
855-
var tc = rootTC.componentViewChildren[0];
856-
var nativeElement = tc.nativeElement;
857-
var updateHost = tc.inject(DirectiveUpdatingHostActions);
858-
859-
ObservableWrapper.subscribe(updateHost.setAttr, (_) => {
860-
expect(DOM.hasAttribute(nativeElement, 'update-host-actions')).toBe(true);
861-
async.done();
862-
});
863-
864-
updateHost.triggerSetAttr('value');
865-
});
866-
}));
867-
}
868-
869844
it('should support render events',
870845
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
871846
tcb.overrideView(

modules/angular2/test/core/compiler/view_manager_utils_spec.ts

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -87,49 +87,20 @@ export function main() {
8787
createHostPv([createNestedElBinder(createComponentPv()), createEmptyElBinder()]);
8888
var hostView = createViewWithChildren(hostPv);
8989
var spyEventAccessor1 = SpyObject.stub({"subscribe": null});
90-
SpyObject.stub(hostView.elementInjectors[0], {
91-
'getHostActionAccessors': [],
92-
'getEventEmitterAccessors': [[spyEventAccessor1]],
93-
'getDirectiveAtIndex': dir
94-
});
90+
SpyObject.stub(
91+
hostView.elementInjectors[0],
92+
{'getEventEmitterAccessors': [[spyEventAccessor1]], 'getDirectiveAtIndex': dir});
9593
var spyEventAccessor2 = SpyObject.stub({"subscribe": null});
96-
SpyObject.stub(hostView.elementInjectors[1], {
97-
'getHostActionAccessors': [],
98-
'getEventEmitterAccessors': [[spyEventAccessor2]],
99-
'getDirectiveAtIndex': dir
100-
});
94+
SpyObject.stub(
95+
hostView.elementInjectors[1],
96+
{'getEventEmitterAccessors': [[spyEventAccessor2]], 'getDirectiveAtIndex': dir});
10197

10298
utils.hydrateRootHostView(hostView, createInjector());
10399

104100
expect(spyEventAccessor1.spy('subscribe')).toHaveBeenCalledWith(hostView, 0, dir);
105101
expect(spyEventAccessor2.spy('subscribe')).toHaveBeenCalledWith(hostView, 1, dir);
106102
});
107103

108-
it("should set up host action listeners", () => {
109-
var dir = new Object();
110-
111-
var hostPv =
112-
createHostPv([createNestedElBinder(createComponentPv()), createEmptyElBinder()]);
113-
var hostView = createViewWithChildren(hostPv);
114-
var spyActionAccessor1 = SpyObject.stub({"subscribe": null});
115-
SpyObject.stub(hostView.elementInjectors[0], {
116-
'getHostActionAccessors': [[spyActionAccessor1]],
117-
'getEventEmitterAccessors': [],
118-
'getDirectiveAtIndex': dir
119-
});
120-
var spyActionAccessor2 = SpyObject.stub({"subscribe": null});
121-
SpyObject.stub(hostView.elementInjectors[1], {
122-
'getHostActionAccessors': [[spyActionAccessor2]],
123-
'getEventEmitterAccessors': [],
124-
'getDirectiveAtIndex': dir
125-
});
126-
127-
utils.hydrateRootHostView(hostView, createInjector());
128-
129-
expect(spyActionAccessor1.spy('subscribe')).toHaveBeenCalledWith(hostView, 0, dir);
130-
expect(spyActionAccessor2.spy('subscribe')).toHaveBeenCalledWith(hostView, 1, dir);
131-
});
132-
133104
it("should not hydrate element injectors of component views inside of embedded fragments",
134105
() => {
135106
var hostView = createViewWithChildren(createHostPv([

modules/angular2/test/core/render/api_spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ export function main() {
88
describe('host', () => {
99
it('should parse host configuration', () => {
1010
var md = RenderDirectiveMetadata.create({
11-
host: MapWrapper.createFromPairs([
12-
['(event)', 'eventVal'],
13-
['[prop]', 'propVal'],
14-
['@action', 'actionVal'],
15-
['attr', 'attrVal']
16-
])
11+
host: MapWrapper.createFromPairs(
12+
[['(event)', 'eventVal'], ['[prop]', 'propVal'], ['attr', 'attrVal']])
1713
});
1814

1915
expect(md.hostListeners).toEqual(MapWrapper.createFromPairs([['event', 'eventVal']]));
2016
expect(md.hostProperties).toEqual(MapWrapper.createFromPairs([['prop', 'propVal']]));
21-
expect(md.hostActions).toEqual(MapWrapper.createFromPairs([['action', 'actionVal']]));
2217
expect(md.hostAttributes).toEqual(MapWrapper.createFromPairs([['attr', 'attrVal']]));
2318
});
2419
});

modules_dart/transform/test/transform/directive_metadata_extractor/all_tests.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ void allTests() {
9797
expect(metadata.hostAttributes.length).toBe(1);
9898
expect(metadata.hostAttributes).toContain('attName');
9999
expect(metadata.hostAttributes['attName']).toEqual('attValue');
100-
101-
expect(metadata.hostActions).toBeNotNull();
102-
expect(metadata.hostActions.length).toBe(1);
103-
expect(metadata.hostActions).toContain('actionName');
104-
expect(metadata.hostActions['actionName']).toEqual('actionValue');
105100
});
106101

107102
it('should parse lifecycle events.', () async {

0 commit comments

Comments
 (0)