Skip to content

Commit adfa250

Browse files
committed
Remove use of Ember.on
no issue - removes the few uses of `Ember.on` for lifecycle hooks or event hooks where order may be important `Ember.on` use is discouraged so although we haven't used it often I felt like we should ensure we're consistent throughout the codebase. There's a great article with details of why it's discouraged here: http://notmessenger.com/proper-use-of-ember-on/
1 parent 4a7a19c commit adfa250

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

core/client/app/components/gh-activating-list-item.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import Ember from 'ember';
22

3-
const {Component, on, run} = Ember;
3+
const {Component, run} = Ember;
44

55
export default Component.extend({
66
tagName: 'li',
77
classNameBindings: ['active'],
88
active: false,
99
linkClasses: null,
1010

11-
unfocusLink: on('click', function () {
11+
click() {
1212
this.$('a').blur();
13-
}),
13+
},
1414

1515
actions: {
1616
setActive(value) {

core/client/app/components/gh-selectize.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Ember from 'ember';
33
import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-selectize';
44

5-
const {computed, isArray, isBlank, get, on, run} = Ember;
5+
const {computed, isArray, isBlank, get, run} = Ember;
66
const emberA = Ember.A;
77

88
export default EmberSelectizeComponent.extend({
@@ -15,28 +15,6 @@ export default EmberSelectizeComponent.extend({
1515
return options;
1616
}),
1717

18-
_dontOpenWhenBlank: on('didInsertElement', function () {
19-
let openOnFocus = this.get('openOnFocus');
20-
21-
if (!openOnFocus) {
22-
run.schedule('afterRender', this, function () {
23-
let selectize = this._selectize;
24-
if (selectize) {
25-
selectize.on('dropdown_open', function () {
26-
if (isBlank(selectize.$control_input.val())) {
27-
selectize.close();
28-
}
29-
});
30-
selectize.on('type', function (filter) {
31-
if (isBlank(filter)) {
32-
selectize.close();
33-
}
34-
});
35-
}
36-
});
37-
}
38-
}),
39-
4018
/**
4119
* Event callback that is triggered when user creates a tag
4220
* - modified to pass the caret position to the action
@@ -105,9 +83,7 @@ export default EmberSelectizeComponent.extend({
10583
// we have a re-order, update the selection
10684
args.forEach((value) => {
10785
let obj = selection.find(function (item) {
108-
// jscs:disable
109-
return (get(item, valuePath) + '') === value;
110-
// jscs:enable
86+
return `${get(item, valuePath)}` === value;
11187
});
11288

11389
if (obj) {
@@ -116,6 +92,33 @@ export default EmberSelectizeComponent.extend({
11692
});
11793

11894
this.set('selection', reorderedSelection);
95+
},
96+
97+
_preventOpeningWhenBlank() {
98+
let openOnFocus = this.get('openOnFocus');
99+
100+
if (!openOnFocus) {
101+
run.schedule('afterRender', this, function () {
102+
let selectize = this._selectize;
103+
if (selectize) {
104+
selectize.on('dropdown_open', function () {
105+
if (isBlank(selectize.$control_input.val())) {
106+
selectize.close();
107+
}
108+
});
109+
selectize.on('type', function (filter) {
110+
if (isBlank(filter)) {
111+
selectize.close();
112+
}
113+
});
114+
}
115+
});
116+
}
117+
},
118+
119+
didInsertElement() {
120+
this._super(...arguments);
121+
this._preventOpeningWhenBlank();
119122
}
120123

121124
});

core/client/app/components/gh-skip-link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*jshint scripturl:true*/
22
import Ember from 'ember';
33

4-
const {$, Component, on} = Ember;
4+
const {$, Component} = Ember;
55

66
export default Component.extend({
77
tagName: 'a',
@@ -15,7 +15,7 @@ export default Component.extend({
1515
// anchor behaviors or ignored
1616
href: Ember.String.htmlSafe('javascript:;'),
1717

18-
scrollTo: on('click', function () {
18+
click() {
1919
let anchor = this.get('anchor');
2020
let $el = Ember.$(anchor);
2121

@@ -32,5 +32,5 @@ export default Component.extend({
3232
$(this).removeAttr('tabindex');
3333
}).focus();
3434
}
35-
})
35+
}
3636
});

core/client/app/components/gh-trim-focus-input.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*global device*/
22
import Ember from 'ember';
33

4-
const {TextField, computed, on} = Ember;
4+
const {TextField, computed} = Ember;
55

66
export default TextField.extend({
77
focus: true,
@@ -16,16 +16,26 @@ export default TextField.extend({
1616
return false;
1717
}),
1818

19-
focusField: on('didInsertElement', function () {
19+
_focusField() {
2020
// This fix is required until Mobile Safari has reliable
2121
// autofocus, select() or focus() support
2222
if (this.get('focus') && !device.ios()) {
2323
this.$().val(this.$().val()).focus();
2424
}
25-
}),
25+
},
2626

27-
trimValue: on('focusOut', function () {
27+
_trimValue() {
2828
let text = this.$().val();
2929
this.$().val(text.trim());
30-
})
30+
},
31+
32+
didInsertElement() {
33+
this._super(...arguments);
34+
this._focusField();
35+
},
36+
37+
focusOut() {
38+
this._super(...arguments);
39+
this._trimValue();
40+
}
3141
});

0 commit comments

Comments
 (0)