Skip to content

Commit

Permalink
Refactored usage of .get('property') with es5 getters
Browse files Browse the repository at this point in the history
no issue
- ran [es5-getter-ember-codemod](https://github.com/rondale-sc/es5-getter-ember-codemod)
- [es5 getters RFC](https://github.com/emberjs/rfcs/blob/master/text/0281-es5-getters.md)
- updates the majority of `object.get('property')` with `object.property` with exceptions:
  - `.get('nested.property')` - it's not possible to determine if this is relying on "safe" path chaining for when `nested` doesn't exist
  - `.get('config.x')` and `.get('settings.x')` - both our `config` and `settings` services are proxy objects which do not support es5 getters
- this PR is not exhaustive, there are still a number of places where `.get('service.foo')` and similar could be replaced but it gets us a long way there in a quick and automated fashion
  • Loading branch information
kevinansfield committed Mar 6, 2019
1 parent ae28198 commit e9c7fad
Show file tree
Hide file tree
Showing 137 changed files with 895 additions and 895 deletions.
2 changes: 1 addition & 1 deletion app/components/gh-alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default Component.extend({

actions: {
closeNotification() {
this.get('notifications').closeNotification(this.get('message'));
this.notifications.closeNotification(this.message);
}
}
});
2 changes: 1 addition & 1 deletion app/components/gh-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default Component.extend({

didReceiveAttrs() {
this._super(...arguments);
let showSettingsMenu = this.get('showSettingsMenu');
let showSettingsMenu = this.showSettingsMenu;

$('body').toggleClass('settings-menu-expanded', showSettingsMenu);
}
Expand Down
4 changes: 2 additions & 2 deletions app/components/gh-basic-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export default BasicDropdown.extend({

didInsertElement() {
this._super(...arguments);
this.get('dropdown').on('close', this, this.close);
this.dropdown.on('close', this, this.close);
},

willDestroyElement() {
this._super(...arguments);
this.get('dropdown').off('close');
this.dropdown.off('close');
}
});
10 changes: 5 additions & 5 deletions app/components/gh-cm-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ const CmEditorComponent = Component.extend({
_value: boundOneWay('value'), // make sure a value exists

didReceiveAttrs() {
if (this.get('_value') === null || undefined) {
if (this._value === null || undefined) {
this.set('_value', '');
}
},

didInsertElement() {
this._super(...arguments);
this.get('initCodeMirror').perform();
this.initCodeMirror.perform();
},

willDestroyElement() {
Expand All @@ -60,15 +60,15 @@ const CmEditorComponent = Component.extend({
},

initCodeMirror: task(function* () {
let loader = this.get('lazyLoader');
let loader = this.lazyLoader;
yield loader.loadScript('codemirror', 'assets/codemirror/codemirror.js');

scheduleOnce('afterRender', this, this._initCodeMirror);
}),

_initCodeMirror() {
let options = this.getProperties('lineNumbers', 'lineWrapping', 'indentUnit', 'mode', 'theme', 'autofocus');
assign(options, {value: this.get('_value')});
assign(options, {value: this._value});

let textarea = this.element.querySelector('textarea');
if (textarea && textarea === document.activeElement) {
Expand Down Expand Up @@ -105,7 +105,7 @@ const CmEditorComponent = Component.extend({

_focus(codeMirror, event) {
this.set('isFocused', true);
once(this, this.get('focus-in'), codeMirror.getValue(), codeMirror, event);
once(this, this['focus-in'], codeMirror.getValue(), codeMirror, event);
},

_blur(/* codeMirror, event */) {
Expand Down
2 changes: 1 addition & 1 deletion app/components/gh-content-cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default Component.extend({
classNames: ['content-cover'],

click() {
this.get('ui').closeMenus();
this.ui.closeMenus();
}
});
42 changes: 21 additions & 21 deletions app/components/gh-date-time-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ export default Component.extend({
hasError: or('dateError', 'timeError'),

timezone: computed('blogTimezone', function () {
let blogTimezone = this.get('blogTimezone');
let blogTimezone = this.blogTimezone;
return moment.utc().tz(blogTimezone).format('z');
}),

dateError: computed('errors.[]', 'dateErrorProperty', function () {
let errors = this.get('errors');
let property = this.get('dateErrorProperty');
let errors = this.errors;
let property = this.dateErrorProperty;

if (errors && !isEmpty(errors.errorsFor(property))) {
return errors.errorsFor(property).get('firstObject').message;
}
}),

timeError: computed('errors.[]', 'timeErrorProperty', function () {
let errors = this.get('errors');
let property = this.get('timeErrorProperty');
let errors = this.errors;
let property = this.timeErrorProperty;

if (errors && !isEmpty(errors.errorsFor(property))) {
return errors.errorsFor(property).get('firstObject').message;
}
}),

didReceiveAttrs() {
let date = this.get('date');
let time = this.get('time');
let minDate = this.get('minDate');
let maxDate = this.get('maxDate');
let blogTimezone = this.get('blogTimezone');
let date = this.date;
let time = this.time;
let minDate = this.minDate;
let maxDate = this.maxDate;
let blogTimezone = this.blogTimezone;

if (!isBlank(date)) {
this.set('_date', moment(date));
Expand All @@ -61,11 +61,11 @@ export default Component.extend({
}

if (isBlank(time)) {
this.set('_time', this.get('_date').format('HH:mm'));
this.set('_time', this._date.format('HH:mm'));
} else {
this.set('_time', this.get('time'));
this.set('_time', this.time);
}
this.set('_previousTime', this.get('_time'));
this.set('_previousTime', this._time);

// unless min/max date is at midnight moment will diable that day
if (minDate === 'now') {
Expand All @@ -89,11 +89,11 @@ export default Component.extend({
// if date or time is set and the other property is blank set that too
// so that we don't get "can't be blank" errors
setDate(date) {
if (date !== this.get('_date')) {
this.get('setDate')(date);
if (date !== this._date) {
this.setDate(date);

if (isBlank(this.get('time'))) {
this.get('setTime')(this.get('_time'));
if (isBlank(this.time)) {
this.setTime(this._time);
}
}
},
Expand All @@ -103,12 +103,12 @@ export default Component.extend({
time = `0${time}`;
}

if (time !== this.get('_previousTime')) {
this.get('setTime')(time);
if (time !== this._previousTime) {
this.setTime(time);
this.set('_previousTime', time);

if (isBlank(this.get('date'))) {
this.get('setDate')(this.get('_date'));
if (isBlank(this.date)) {
this.setDate(this._date);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/components/gh-download-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export default Component.extend({
count: '',

didInsertElement() {
this.get('_poll').perform();
this._poll.perform();
},

_poll: task(function* () {
let url = this.get('ghostPaths.count');
let pattern = /(-?\d+)(\d{3})/;

try {
let data = yield this.get('ajax').request(url);
let data = yield this.ajax.request(url);
let count = data.count.toString();

while (pattern.test(count)) {
Expand All @@ -30,7 +30,7 @@ export default Component.extend({

if (config.environment !== 'test') {
yield timeout(2000);
this.get('_poll').perform();
this._poll.perform();
}
} catch (e) {
// no-op - we don't want to create noise for a failed download count
Expand Down
4 changes: 2 additions & 2 deletions app/components/gh-dropdown-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default Component.extend(DropdownMixin, {
// Notify dropdown service this dropdown should be toggled
click(event) {
this._super(event);
this.get('dropdown').toggleDropdown(this.get('dropdownName'), this);
this.dropdown.toggleDropdown(this.dropdownName, this);

if (this.get('tagName') === 'a') {
if (this.tagName === 'a') {
return false;
}
}
Expand Down
20 changes: 10 additions & 10 deletions app/components/gh-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default Component.extend(DropdownMixin, {

// Managed the toggle between the fade-in and fade-out classes
fadeIn: computed('isOpen', 'closing', function () {
return this.get('isOpen') && !this.get('closing');
return this.isOpen && !this.closing;
}),

didInsertElement() {
let dropdownService = this.get('dropdown');
let dropdownService = this.dropdown;

this._super(...arguments);

Expand All @@ -34,7 +34,7 @@ export default Component.extend(DropdownMixin, {
},

willDestroyElement() {
let dropdownService = this.get('dropdown');
let dropdownService = this.dropdown;

this._super(...arguments);

Expand All @@ -51,14 +51,14 @@ export default Component.extend(DropdownMixin, {
close() {
this.set('closing', true);

if (this.get('button')) {
if (this.button) {
this.set('button.isOpen', false);
}

this.$().on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', (event) => {
if (event.originalEvent.animationName === 'fade-out') {
run(this, function () {
if (this.get('closing')) {
if (this.closing) {
this.set('isOpen', false);
this.set('closing', false);
}
Expand All @@ -69,11 +69,11 @@ export default Component.extend(DropdownMixin, {

// Called by the dropdown service when any dropdown button is clicked.
toggle(options) {
let isClosing = this.get('closing');
let isOpen = this.get('isOpen');
let name = this.get('name');
let isClosing = this.closing;
let isOpen = this.isOpen;
let name = this.name;
let targetDropdownName = options.target;
let button = this.get('button');
let button = this.button;

if (name === targetDropdownName && (!isOpen || isClosing)) {
if (!button) {
Expand All @@ -89,7 +89,7 @@ export default Component.extend(DropdownMixin, {
click(event) {
this._super(event);

if (this.get('closeOnClick')) {
if (this.closeOnClick) {
return this.close();
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/components/gh-editor-post-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default Component.extend({
// we want to ensure that the "Saving..." message is shown for at least
// a few seconds so that it's noticeable
didReceiveAttrs() {
if (this.get('isSaving')) {
this.get('showSavingMessage').perform();
if (this.isSaving) {
this.showSavingMessage.perform();
}
},

Expand Down
4 changes: 2 additions & 2 deletions app/components/gh-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default Component.extend({
actions: {
toggleFullScreen(isFullScreen) {
this.set('isFullScreen', isFullScreen);
this.get('ui').set('isFullScreen', isFullScreen);
this.ui.set('isFullScreen', isFullScreen);
run.scheduleOnce('afterRender', this, this._setHeaderClass);
},

Expand Down Expand Up @@ -90,7 +90,7 @@ export default Component.extend({

this._editorTitleElement = editorTitle;

if (this.get('isSplitScreen')) {
if (this.isSplitScreen) {
this.set('headerClass', smallHeaderClass);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions app/components/gh-error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default Component.extend({
isVisible: notEmpty('errors'),

message: computed('errors.[]', 'property', function () {
let property = this.get('property');
let errors = this.get('errors');
let property = this.property;
let errors = this.errors;
let messages = [];
let index;

Expand Down
16 changes: 8 additions & 8 deletions app/components/gh-feature-flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ const FeatureFlagComponent = Component.extend({
classNames: 'checkbox',
attributeBindings: ['for', 'disabled'],
disabled: computed('_disabled', function () {
if (this.get('_disabled')) {
if (this._disabled) {
return true;
}
return false;
}),
value: computed('_flagValue', {
get() {
return this.get('_flagValue');
return this._flagValue;
},
set(key, value) {
if (this.get('flag') === 'members' && value === true) {
if (this.flag === 'members' && value === true) {
this.set(`feature.subscribers`, false);
}
return this.set(`feature.${this.get('flag')}`, value);
return this.set(`feature.${this.flag}`, value);
}
}),

for: computed('flag', function () {
return `labs-${this.get('flag')}`;
return `labs-${this.flag}`;
}),

name: computed('flag', function () {
return `labs[${this.get('flag')}]`;
return `labs[${this.flag}]`;
}),

init() {
this._super(...arguments);

defineProperty(this, '_flagValue', readOnly(`feature.${this.get('flag')}`), function () {
return this.get(`feature.${this.get('flag')}`);
defineProperty(this, '_flagValue', readOnly(`feature.${this.flag}`), function () {
return this.get(`feature.${this.flag}`);
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion app/components/gh-file-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import XFileInput from 'emberx-file-input/components/x-file-input';

export default XFileInput.extend({
change(e) {
let action = this.get('action');
let action = this.action;
let files = this.files(e);

if (files.length && action) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/gh-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export default Component.extend({

actions: {
upload() {
if (!this.get('uploadButtonDisabled') && this._file) {
if (!this.uploadButtonDisabled && this._file) {
this.onUpload(this._file);
}

// Prevent double post by disabling the button.
this.set('uploadButtonDisabled', true);

// Reset form
if (this.get('shouldResetForm')) {
if (this.shouldResetForm) {
this.$().closest('form')[0].reset();
}
}
Expand Down
Loading

0 comments on commit e9c7fad

Please sign in to comment.