Skip to content

Commit cf41483

Browse files
committed
cleanup + some es6ification
1 parent 7882a4e commit cf41483

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+393
-344
lines changed

app/adapters/dependency.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import ApplicationAdapter from './application';
22

33
export default ApplicationAdapter.extend({
4-
findQuery: function(store, type, query) {
4+
findQuery(store, type, query) {
55
if (!query.reverse) {
6-
return this._super(store, type, query);
6+
return this._super(...arguments);
77
}
88
delete query.reverse;
99
var crate = query.crate;

app/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var App = Ember.Application.extend({
1212
});
1313

1414
loadInitializers(App, config.modulePrefix);
15-
Ember.$.ajaxSetup({cache: false});
15+
Ember.$.ajaxSetup({
16+
cache: false
17+
});
1618

1719
export default App;

app/components/user-avatar.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import Ember from 'ember';
22

3+
const { computed } = Ember;
4+
35
export default Ember.Component.extend({
46
size: 'small',
57
user: null,
68
attributeBindings: ['src', 'width', 'height'],
79
tagName: 'img',
810

9-
width: function() {
11+
width: computed('size', function() {
1012
if (this.get('size') === 'small') {
1113
return 22;
1214
} else if (this.get('size') === 'medium-small') {
1315
return 32;
1416
} else {
1517
return 85; // medium
1618
}
17-
}.property('size'),
19+
}),
1820

19-
height: function() {
20-
return this.get('width');
21-
}.property('width'),
21+
height: computed.readOnly('width'),
2222

23-
src: function() {
23+
src: computed('size', 'user', function() {
2424
return this.get('user.avatar') + '&s=' + this.get('width');
25-
}.property('size', 'user'),
25+
})
2626
});

app/components/user-link.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import Ember from 'ember';
22

3+
const { computed } = Ember;
4+
35
export default Ember.Component.extend({
46
user: null,
57
attributeBindings: ['title', 'href'],
68
tagName: 'a',
79

8-
title: function() {
9-
return this.get('user.login');
10-
}.property('user'),
11-
12-
'href': function() {
10+
title: computed.readOnly('user.login'),
11+
href: computed('user', function() {
1312
// TODO replace this with a link to a native crates.io profile
1413
// page when they exist.
15-
return 'https://github.com/' + this.get('user.login');
16-
}.property('user'),
14+
return `https://github.com/${this.get('user.login')}`;
15+
})
1716
});

app/controllers/application.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Ember from 'ember';
22

3+
const { observer } = Ember;
4+
35
export default Ember.Controller.extend({
46
needs: ['search'],
57

@@ -8,44 +10,53 @@ export default Ember.Controller.extend({
810
showUserOptions: false,
911
search: Ember.computed.oneWay('controllers.search.q'),
1012

11-
stepFlash: function() {
13+
stepFlash() {
1214
this.set('flashError', this.get('nextFlashError'));
1315
this.set('nextFlashError', null);
1416
},
1517

16-
aboutToTransition: function() {
18+
aboutToTransition() {
1719
Ember.$(document).trigger('mousedown');
1820
},
1921

20-
resetDropdownOption: function(controller, option) {
21-
controller.set(option, !controller.get(option));
22-
if (controller.get(option)) {
23-
Ember.$(document).on('mousedown.useroptions', function(e) {
22+
// don't use this from other controllers..
23+
resetDropdownOption(controller, option) {
24+
this.set(option, !this.get(option));
25+
if (this.get(option)) {
26+
Ember.$(document).on('mousedown.useroptions', (e) => {
2427
if (Ember.$(e.target).prop('tagName') === 'INPUT') {
2528
return;
2629
}
27-
Ember.run.later(function() {
28-
controller.set(option, false);
30+
Ember.run.later(() => {
31+
this.set(option, false);
2932
}, 150);
3033
Ember.$(document).off('mousedown.useroptions');
3134
});
3235
}
3336
},
3437

35-
currentPathChanged: function () {
38+
_scrollToTop() {
3639
window.scrollTo(0, 0);
37-
}.observes('currentPath'),
40+
},
41+
42+
// TODO: remove observer & DOM mutation in controller..
43+
currentPathChanged: observer('currentPath', function () {
44+
Ember.run.scheduleOnce('afterRender', this, this._scrollToTop);
45+
}),
3846

3947
actions: {
40-
search: function(query) {
48+
search(q) {
4149
this.transitionToRoute('search', {
42-
queryParams: {q: query, page: 1}
50+
queryParams: {
51+
q,
52+
page: 1
53+
}
4354
});
4455
},
4556

46-
toggleUserOptions: function() {
57+
toggleUserOptions() {
4758
this.resetDropdownOption(this, 'showUserOptions');
48-
},
49-
},
59+
}
60+
}
5061
});
5162

app/controllers/catch-all.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Ember from 'ember';
22

33
export default Ember.Controller.extend({
44
actions: {
5-
search: function(query) {
5+
search(query) {
66
return this.transitionToRoute('search', {queryParams: {q: query}});
77
},
88
},

0 commit comments

Comments
 (0)