0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Avoid use of this.attrs for closure actions

no issue
- `this.attrs` is a glimmer-component thing (which doesn't exist in Ghost yet), to avoid confusion we should avoid using it
- https://locks.svbtle.com/to-attrs-or-not-to-attrs
- https://github.com/cibernox/ember-power-select/issues/233#issuecomment-170352572
This commit is contained in:
Kevin Ansfield 2016-04-06 16:26:58 +01:00
parent d542ae86df
commit 0c136a5a23
16 changed files with 66 additions and 27 deletions

View file

@ -17,7 +17,7 @@ export default Component.extend(TextInputMixin, {
didReceiveAttrs() { didReceiveAttrs() {
let datetime = this.get('datetime') || moment(); let datetime = this.get('datetime') || moment();
if (!this.attrs.update) { if (!this.get('update')) {
throw new Error(`You must provide an \`update\` action to \`{{${this.templateName}}}\`.`); throw new Error(`You must provide an \`update\` action to \`{{${this.templateName}}}\`.`);
} }
@ -27,6 +27,6 @@ export default Component.extend(TextInputMixin, {
focusOut() { focusOut() {
let datetime = this.get('datetime'); let datetime = this.get('datetime');
this.attrs.update(datetime); this.get('update')(datetime);
} }
}); });

View file

@ -32,7 +32,7 @@ export default TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, {
this.setFocus(); this.setFocus();
this.attrs.setEditor(this); this.get('setEditor')(this);
run.scheduleOnce('afterRender', this, this.afterRenderEvent); run.scheduleOnce('afterRender', this, this.afterRenderEvent);
}, },
@ -45,7 +45,7 @@ export default TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, {
actions: { actions: {
toggleCopyHTMLModal(generatedHTML) { toggleCopyHTMLModal(generatedHTML) {
this.attrs.toggleCopyHTMLModal(generatedHTML); this.get('toggleCopyHTMLModal')(generatedHTML);
} }
} }
}); });

View file

@ -52,8 +52,8 @@ export default Component.extend(ShortcutsMixin, {
}, },
willDestroyElement() { willDestroyElement() {
if (this.attrs.onTeardown) { if (this.get('onTeardown')) {
this.attrs.onTeardown(); this.get('onTeardown')();
} }
this.removeShortcuts(); this.removeShortcuts();
}, },

View file

@ -50,8 +50,8 @@ const FullScreenModalComponent = LiquidTether.extend({
actions: { actions: {
close() { close() {
if (this.attrs.close) { if (this.get('close')) {
return this.attrs.close(); return this.get('close')();
} }
return new Promise((resolve) => { return new Promise((resolve) => {
@ -60,8 +60,8 @@ const FullScreenModalComponent = LiquidTether.extend({
}, },
confirm() { confirm() {
if (this.attrs.confirm) { if (this.get('confirm')) {
return this.attrs.confirm(); return this.get('confirm')();
} }
return new Promise((resolve) => { return new Promise((resolve) => {

View file

@ -67,7 +67,7 @@ export default TextField.extend({
}, },
keyPress(event) { keyPress(event) {
this.attrs.clearErrors(); this.get('clearErrors')();
// enter key // enter key
if (event.keyCode === 13) { if (event.keyCode === 13) {

View file

@ -50,8 +50,8 @@ export default Component.extend(ActiveLinkWrapper, {
willDestroyElement() { willDestroyElement() {
this._super(...arguments); this._super(...arguments);
this.removeObserver('active', this, this.scrollIntoView); this.removeObserver('active', this, this.scrollIntoView);
if (this.get('post.isDeleted') && this.attrs.onDelete) { if (this.get('post.isDeleted') && this.get('onDelete')) {
this.attrs.onDelete(); this.get('onDelete')();
} }
}, },

View file

@ -108,15 +108,15 @@ export default Component.extend({
actions: { actions: {
setProperty(property, value) { setProperty(property, value) {
this.attrs.setProperty(property, value); this.get('setProperty')(property, value);
}, },
setCoverImage(image) { setCoverImage(image) {
this.attrs.setProperty('image', image); this.get('setProperty')('image', image);
}, },
clearCoverImage() { clearCoverImage() {
this.attrs.setProperty('image', ''); this.get('setProperty')('image', '');
}, },
setUploaderReference() { setUploaderReference() {
@ -132,7 +132,7 @@ export default Component.extend({
}, },
deleteTag() { deleteTag() {
this.attrs.showDeleteTagModal(); this.get('showDeleteTagModal')();
} }
} }

View file

@ -4,8 +4,8 @@ export default Ember.Component.extend({
willDestroyElement() { willDestroyElement() {
this._super(...arguments); this._super(...arguments);
if (this.get('tag.isDeleted') && this.attrs.onDelete) { if (this.get('tag.isDeleted') && this.get('onDelete')) {
this.attrs.onDelete(); this.get('onDelete')();
} }
} }
}); });

View file

@ -49,7 +49,7 @@ export default Component.extend({
}, },
closeModal() { closeModal() {
this.attrs.closeModal(); this.get('closeModal')();
} }
} }
}); });

View file

@ -18,7 +18,7 @@ export default ModalComponent.extend({
confirm() { confirm() {
this.set('submitting', true); this.set('submitting', true);
this.attrs.confirm().finally(() => { this.get('confirm')().finally(() => {
this.send('closeModal'); this.send('closeModal');
}); });
} }

View file

@ -10,7 +10,7 @@ export default ModalComponent.extend({
confirm() { confirm() {
this.set('submitting', true); this.set('submitting', true);
this.attrs.confirm().finally(() => { this.get('confirm')().finally(() => {
this.send('closeModal'); this.send('closeModal');
}); });
} }

View file

@ -3,7 +3,7 @@ import ModalComponent from 'ghost/components/modals/base';
export default ModalComponent.extend({ export default ModalComponent.extend({
actions: { actions: {
confirm() { confirm() {
this.attrs.confirm().finally(() => { this.get('confirm').finally(() => {
this.send('closeModal'); this.send('closeModal');
}); });
} }

View file

@ -8,7 +8,7 @@ export default ModalComponent.extend({
confirm() { confirm() {
this.set('submitting', true); this.set('submitting', true);
this.attrs.confirm().finally(() => { this.get('confirm')().finally(() => {
this.send('closeModal'); this.send('closeModal');
}); });
} }

View file

@ -61,7 +61,7 @@ export default Mixin.create({
*/ */
scrollHandler() { scrollHandler() {
this.set('scrollThrottle', run.throttle(this, () => { this.set('scrollThrottle', run.throttle(this, () => {
this.attrs.updateScrollInfo(this.getScrollInfo()); this.get('updateScrollInfo')(this.getScrollInfo());
}, 10)); }, 10));
}, },

View file

@ -6,8 +6,8 @@ LinkComponent.reopen({
active: computed('attrs.params', '_routing.currentState', function () { active: computed('attrs.params', '_routing.currentState', function () {
let isActive = this._super(...arguments); let isActive = this._super(...arguments);
if (typeof this.attrs.alternateActive === 'function') { if (typeof this.get('alternateActive') === 'function') {
this.attrs.alternateActive(isActive); this.get('alternateActive')(isActive);
} }
return isActive; return isActive;

View file

@ -0,0 +1,39 @@
/* jshint expr:true */
import { expect } from 'chai';
import {
describeComponent,
it
} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';
import sinon from 'sinon';
const {RSVP, run} = Ember;
describeComponent(
'transfer-owner',
'Integration: Component: modals/transfer-owner',
{
integration: true
},
function() {
it('triggers confirm action', function() {
let confirm = sinon.stub();
let closeModal = sinon.spy();
confirm.returns(RSVP.resolve({}));
this.on('confirm', confirm);
this.on('closeModal', closeModal);
this.render(hbs`{{modals/transfer-owner confirm=(action 'confirm') closeModal=(action 'closeModal')}}`);
run(() => {
this.$('.btn.btn-red').click();
});
expect(confirm.calledOnce, 'confirm called').to.be.true;
expect(closeModal.calledOnce, 'closeModal called').to.be.true;
});
}
);