Skip to content

Migrate services to native classes #2290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/services/fetcher.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Service, { inject as service } from '@ember/service';
import ajax from 'ember-fetch/ajax';

export default Service.extend({
fastboot: service(),
export default class FetcherService extends Service {
@service fastboot;

ajax(url) {
let fastboot = this.fastboot;
Expand All @@ -23,8 +23,8 @@ export default Service.extend({
}
return resp;
});
},
});
}
}

function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj));
Expand Down
14 changes: 7 additions & 7 deletions app/services/flash-messages.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Service from '@ember/service';

export default Service.extend({
message: null,
_nextMessage: null,
export default class FlashMessagesService extends Service {
message = null;
_nextMessage = null;

show(message) {
this.set('message', message);
},
}

queue(message) {
this.set('_nextMessage', message);
},
}

step() {
this.set('message', this._nextMessage);
this.set('_nextMessage', null);
},
});
}
}
8 changes: 4 additions & 4 deletions app/services/redirector.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Service, { inject as service } from '@ember/service';
import window from 'ember-window-mock';

export default Service.extend({
fastboot: service(),
export default class RedirectorService extends Service {
@service fastboot;

redirectTo(url) {
if (this.fastboot.isFastBoot) {
Expand All @@ -12,5 +12,5 @@ export default Service.extend({
} else {
window.location = url;
}
},
});
}
}
6 changes: 3 additions & 3 deletions app/services/search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Service from '@ember/service';

export default Service.extend({
q: null,
});
export default class SearchService extends Service {
q = null;
}
37 changes: 19 additions & 18 deletions app/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import Service, { inject as service } from '@ember/service';
import ajax from 'ember-fetch/ajax';
import window from 'ember-window-mock';

export default Service.extend({
savedTransition: null,
abortedTransition: null,
isLoggedIn: false,
currentUser: null,
currentUserDetected: false,
ownedCrates: A(),
export default class SessionService extends Service {
@service store;
@service router;

store: service(),
router: service(),
savedTransition = null;
abortedTransition = null;
isLoggedIn = false;
currentUser = null;
currentUserDetected = false;
ownedCrates = A();

constructor() {
super(...arguments);

init() {
this._super(...arguments);
let isLoggedIn;
try {
isLoggedIn = window.localStorage.getItem('isLoggedIn') === '1';
Expand All @@ -24,7 +25,7 @@ export default Service.extend({
}
this.set('isLoggedIn', isLoggedIn);
this.set('currentUser', null);
},
}

loginUser(user) {
this.set('isLoggedIn', true);
Expand All @@ -34,7 +35,7 @@ export default Service.extend({
} catch (e) {
// ignore error
}
},
}

logoutUser() {
this.set('savedTransition', null);
Expand All @@ -47,7 +48,7 @@ export default Service.extend({
} catch (e) {
// ignore error
}
},
}

loadUser() {
if (this.isLoggedIn && !this.currentUser) {
Expand All @@ -64,7 +65,7 @@ export default Service.extend({
} else {
this.set('currentUserDetected', true);
}
},
}

fetchUser() {
return ajax('/api/v1/me').then(response => {
Expand All @@ -73,7 +74,7 @@ export default Service.extend({
response.owned_crates.map(c => this.store.push(this.store.normalize('owned-crate', c))),
);
});
},
}

checkCurrentUser(transition, beforeRedirect) {
if (this.currentUser) {
Expand All @@ -94,5 +95,5 @@ export default Service.extend({
}
return this.router.transitionTo('index');
}
},
});
}
}