Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Update assertion for events in tagless component to include method names #17930

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ViewStateSupport,
} from '@ember/-internals/views';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { DirtyableTag } from '@glimmer/reference';
import { normalizeProperty, SVG_NAMESPACE } from '@glimmer/runtime';

Expand Down Expand Up @@ -727,27 +728,26 @@ const Component = CoreView.extend(
this[ROOT_REF] = new RootReference(this);
this[BOUNDS] = null;

// If in a tagless component, assert that no event handlers are defined
assert(
// tslint:disable-next-line:max-line-length
`You can not define a function that handles DOM events in the \`${this}\` tagless component since it doesn't have any DOM element.`,
this.tagName !== '' ||
!this.renderer._destinedForDOM ||
!(() => {
let eventDispatcher = getOwner(this).lookup<any | undefined>('event_dispatcher:main');
let events = (eventDispatcher && eventDispatcher._finalEvents) || {};

// tslint:disable-next-line:forin
for (let key in events) {
let methodName = events[key];

if (typeof this[methodName] === 'function') {
return true; // indicate that the assertion should be triggered
}
}
return false;
})()
);
if (DEBUG && this.renderer._destinedForDOM && this.tagName === '') {
let eventNames = [];
let eventDispatcher = getOwner(this).lookup<any | undefined>('event_dispatcher:main');
let events = (eventDispatcher && eventDispatcher._finalEvents) || {};

// tslint:disable-next-line:forin
for (let key in events) {
let methodName = events[key];

if (typeof this[methodName] === 'function') {
eventNames.push(methodName);
}
}
// If in a tagless component, assert that no event handlers are defined
assert(
// tslint:disable-next-line:max-line-length
`You can not define \`${eventNames}\` function(s) to handle DOM event in the \`${this}\` tagless component since it doesn't have any DOM element.`,
!eventNames.length
);
}
},

rerender() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ moduleFor(
let FooBarComponent = Component.extend({
tagName: '',
click() {},
mouseEnter() {},
});

this.registerComponent('foo-bar', {
Expand All @@ -66,7 +67,7 @@ moduleFor(

expectAssertion(() => {
this.render(`{{#foo-bar}}{{/foo-bar}}`);
}, /You can not define a function that handles DOM events in the .* tagless component since it doesn't have any DOM element./);
}, /You can not define `click,mouseEnter` function\(s\) to handle DOM event in the .* tagless component since it doesn't have any DOM element./);
}

['@test throws an error if a custom defined event function is defined in a tagless component']() {
Expand All @@ -83,7 +84,7 @@ moduleFor(

expectAssertion(() => {
this.render(`{{#foo-bar}}{{/foo-bar}}`);
}, /You can not define a function that handles DOM events in the .* tagless component since it doesn't have any DOM element./);
}, /You can not define `folks` function\(s\) to handle DOM event in the .* tagless component since it doesn't have any DOM element./);
}

['@test throws an error if `tagName` is an empty string and `classNameBindings` are specified']() {
Expand Down