Always use closure actions

no issue
- https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/closure-actions.md
This commit is contained in:
Kevin Ansfield 2017-11-24 23:18:35 +00:00
parent f9d30ff9c8
commit 1a4909ea34
18 changed files with 90 additions and 55 deletions

View File

@ -5,7 +5,10 @@ import XFileInput from 'emberx-file-input/components/x-file-input';
export default XFileInput.extend({
change(e) {
this.sendAction('action', this.files(e), this.resetInput.bind(this));
let action = this.get('action');
if (action) {
action(this.files(e), this.resetInput.bind(this));
}
},
/**

View File

@ -1,5 +1,4 @@
import Component from '@ember/component';
import {invokeAction} from 'ember-invoke-action';
export default Component.extend({
@ -7,25 +6,31 @@ export default Component.extend({
actions: {
update() {
if (typeof this.attrs.update === 'function') {
this.attrs.update(...arguments);
let action = this.get('update');
if (action) {
action(...arguments);
}
},
uploadStarted() {
if (typeof this.attrs.uploadStarted === 'function') {
this.attrs.uploadStarted(...arguments);
let action = this.get('uploadStarted');
if (action) {
action(...arguments);
}
},
uploadFinished() {
if (typeof this.attrs.uploadFinished === 'function') {
this.attrs.uploadFinished(...arguments);
let action = this.get('uploadFinished');
if (action) {
action(...arguments);
}
},
remove() {
invokeAction(this, 'remove');
let action = this.get('remove');
if (action) {
action();
}
}
}
});

View File

@ -6,6 +6,9 @@ export default Component.extend({
ariaRole: 'main',
mouseEnter() {
this.sendAction('onMouseEnter');
let action = this.get('onMouseEnter');
if (action) {
action();
}
}
});

View File

@ -27,10 +27,6 @@ export default Component.extend({
this._setIconStyle();
},
mouseEnter() {
this.sendAction('onMouseEnter');
},
showMenuExtension: computed('config.clientExtensions.menu', 'session.user.isOwner', function() {
return this.get('config.clientExtensions.menu') && this.get('session.user.isOwner');
}),

View File

@ -142,6 +142,9 @@ export default TextField.extend(InvokeActionMixin, {
}
}
this.sendAction('change', url);
let action = this.get('update');
if (action) {
action(url);
}
}
});

View File

@ -31,19 +31,31 @@ export default Component.extend(ValidationState, {
actions: {
addItem() {
this.sendAction('addItem');
let action = this.get('addItem');
if (action) {
action();
}
},
deleteItem(item) {
this.sendAction('deleteItem', item);
let action = this.get('deleteItem');
if (action) {
action(item);
}
},
updateUrl(value) {
this.sendAction('updateUrl', value, this.get('navItem'));
let action = this.get('updateUrl');
if (action) {
action(value, this.get('navItem'));
}
},
updateLabel(value) {
this.sendAction('updateLabel', value, this.get('navItem'));
let action = this.get('updateLabel');
if (action) {
action(value, this.get('navItem'));
}
},
clearLabelErrors() {

View File

@ -122,7 +122,10 @@ export default Component.extend({
let fileName = data.files[0].name;
if ((/\.(gif|jpe?g|png|svg?z)$/i).test(fileName)) {
this.sendAction('setImage', data);
let action = this.get('setImage');
if (action) {
action(data);
}
}
},

View File

@ -44,7 +44,10 @@ export default Component.extend({
fireMobileChangeActions: observer('isMobile', function () {
if (!this.get('isMobile')) {
this.sendAction('leftMobile');
let action = this.get('leftMobile');
if (action) {
action();
}
}
})
});

View File

@ -33,6 +33,7 @@ const UploadTracker = EmberObject.extend({
loaded: 0,
init() {
this._super(...arguments);
this.total = this.file && this.file.size || 0;
},

View File

@ -76,7 +76,11 @@ export default Component.extend({
}).catch((error) => {
if (isNotFoundError(error)) {
// if the invite no longer exists, then show a warning and reload the route
this.sendAction('reload');
let action = this.get('reload');
if (action) {
action();
}
notifications.showAlert('This invite has been revoked or a user has already accepted the invitation.', {type: 'error', delayed: true, key: 'invite.revoke.already-accepted'});
} else {
throw error;

View File

@ -11,7 +11,7 @@
{{gh-error-message errors=navItem.errors property="label"}}
{{/gh-validation-status-container}}
{{#gh-validation-status-container tagName="span" class="gh-blognav-url" errors=navItem.errors property="url" hasValidated=navItem.hasValidated}}
{{gh-navitem-url-input baseUrl=baseUrl url=navItem.url isNew=navItem.isNew change="updateUrl" clearErrors=(action "clearUrlErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=navItem.url isNew=navItem.isNew update=(action "updateUrl") clearErrors=(action "clearUrlErrors")}}
{{gh-error-message errors=navItem.errors property="url"}}
{{/gh-validation-status-container}}
</div>

View File

@ -20,11 +20,11 @@
{{#sortable-objects sortableObjectList=model.navigation useSwap=false}}
{{#each model.navigation as |navItem|}}
{{#draggable-object content=navItem dragHandle=".gh-blognav-grab" isSortable=true}}
{{gh-navitem navItem=navItem baseUrl=blogUrl addItem="addNavItem" deleteItem="deleteNavItem" updateUrl="updateUrl" updateLabel="updateLabel"}}
{{gh-navitem navItem=navItem baseUrl=blogUrl addItem=(action "addNavItem") deleteItem=(action "deleteNavItem") updateUrl=(action "updateUrl") updateLabel=(action "updateLabel")}}
{{/draggable-object}}
{{/each}}
{{/sortable-objects}}
{{gh-navitem navItem=newNavItem baseUrl=blogUrl addItem="addNavItem" updateUrl="updateUrl"}}
{{gh-navitem navItem=newNavItem baseUrl=blogUrl addItem=(action "addNavItem") updateUrl=(action "updateUrl")}}
</form>
</div>

View File

@ -6,7 +6,7 @@
</section>
</header>
{{#gh-tags-management-container tags=tags selectedTag=selectedTag enteredMobile="enteredMobile" leftMobile="leftMobile" as |container|}}
{{#gh-tags-management-container tags=tags selectedTag=selectedTag enteredMobile="enteredMobile" leftMobile=(action "leftMobile") as |container|}}
<div class="tag-list">
<section class="tag-list-content settings-tags {{if tagListFocused 'keyboard-focused'}}">
{{#vertical-collection sortedTags

View File

@ -25,7 +25,7 @@
<div class="apps-grid">
{{#each sortedInvites as |invite|}}
{{#gh-user-invited invite=invite reload="reload" as |component|}}
{{#gh-user-invited invite=invite reload=(route-action "reload") as |component|}}
<div class="apps-grid-cell" data-test-invite-id="{{invite.id}}">
<article class="apps-card-app">
<div class="apps-card-left">

View File

@ -257,6 +257,7 @@ describe('Acceptance: Authentication', function () {
// necessary to visit a page to fully boot the app in testing
await visit('/');
/* eslint-disable ember/jquery-ember-run */
await $.ajax({
type: 'POST',
url: `${Ghost.apiRoot}/uploads/`,
@ -269,5 +270,6 @@ describe('Acceptance: Authentication', function () {
}).always(() => {
done();
});
/* eslint-enable ember/jquery-ember-run */
});
});

View File

@ -60,7 +60,7 @@ describe('Integration: Component: gh-navitem', function () {
deleteActionCallCount++;
});
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl deleteItem="deleteItem"}}`);
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl deleteItem=(action "deleteItem")}}`);
this.$('.gh-blognav-delete').trigger('click');
expect(deleteActionCallCount).to.equal(1);
@ -74,7 +74,7 @@ describe('Integration: Component: gh-navitem', function () {
addActionCallCount++;
});
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl addItem="add"}}`);
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl addItem=(action "add")}}`);
this.$('.gh-blognav-add').trigger('click');
expect(addActionCallCount).to.equal(1);
@ -88,7 +88,7 @@ describe('Integration: Component: gh-navitem', function () {
updateActionCallCount++;
});
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl updateUrl="update"}}`);
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl updateUrl=(action "update")}}`);
this.$('.gh-blognav-url input').trigger('blur');
expect(updateActionCallCount).to.equal(1);
@ -102,7 +102,7 @@ describe('Integration: Component: gh-navitem', function () {
updateActionCallCount++;
});
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl updateLabel="update"}}`);
this.render(hbs`{{gh-navitem navItem=navItem baseUrl=baseUrl updateLabel=(action "update")}}`);
this.$('.gh-blognav-label input').trigger('blur');
expect(updateActionCallCount).to.equal(1);

View File

@ -27,7 +27,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
it('renders correctly with blank url', function () {
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -39,7 +39,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
it('renders correctly with relative urls', function () {
this.set('url', '/about');
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -52,7 +52,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
it('renders correctly with absolute urls', function () {
this.set('url', 'https://example.com:2368/#test');
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -73,7 +73,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
it('deletes base URL on backspace', function () {
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -90,7 +90,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
it('deletes base URL on delete', function () {
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -110,7 +110,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
return null;
});
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -129,7 +129,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
return null;
});
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -154,7 +154,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
return null;
});
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -176,7 +176,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
return null;
});
this.render(hbs`
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -187,14 +187,14 @@ describe('Integration: Component: gh-navitem-url-input', function () {
expect($input.val()).to.equal(`${currentUrl} /test`);
});
it('triggers "change" action on blur', function () {
it('triggers "update" action on blur', function () {
let changeActionCallCount = 0;
this.on('updateUrl', () => {
changeActionCallCount++;
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -203,14 +203,14 @@ describe('Integration: Component: gh-navitem-url-input', function () {
expect(changeActionCallCount).to.equal(1);
});
it('triggers "change" action on enter', function () {
it('triggers "update" action on enter', function () {
let changeActionCallCount = 0;
this.on('updateUrl', () => {
changeActionCallCount++;
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -225,14 +225,14 @@ describe('Integration: Component: gh-navitem-url-input', function () {
expect(changeActionCallCount).to.equal(1);
});
it('triggers "change" action on CMD-S', function () {
it('triggers "update" action on CMD-S', function () {
let changeActionCallCount = 0;
this.on('updateUrl', () => {
changeActionCallCount++;
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -256,7 +256,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -289,7 +289,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -318,7 +318,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -337,7 +337,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -363,7 +363,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -391,7 +391,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -424,7 +424,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');
@ -451,7 +451,7 @@ describe('Integration: Component: gh-navitem-url-input', function () {
});
this.render(hbs `
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew change="updateUrl" clearErrors=(action "clearErrors")}}
{{gh-navitem-url-input baseUrl=baseUrl url=url isNew=isNew update=(action "updateUrl") clearErrors=(action "clearErrors")}}
`);
let $input = this.$('input');

View File

@ -20,7 +20,7 @@ describe('Integration: Component: gh-tags-management-container', function () {
});
this.render(hbs`
{{#gh-tags-management-container tags=tags selectedTag=selectedTag enteredMobile="enteredMobile" leftMobile="leftMobile"}}{{/gh-tags-management-container}}
{{#gh-tags-management-container tags=tags selectedTag=selectedTag enteredMobile="enteredMobile" leftMobile=(action "leftMobile")}}{{/gh-tags-management-container}}
`);
expect(this.$()).to.have.length(1);
});