More code optimization

This commit is contained in:
An Phan 2016-05-05 18:38:54 +08:00
parent 80900f17cb
commit f8c7233cd9
4 changed files with 6 additions and 18 deletions

View file

@ -44,11 +44,7 @@ export default {
// This may cause a minor problem if the request fails somehow, but do we care?
song.liked = !song.liked;
if (song.liked) {
this.add(song);
} else {
this.remove(song);
}
song.liked ? this.add(song) : this.remove(song);
http.post('interaction/like', { song: song.id }, () => cb && cb());
},

View file

@ -218,9 +218,7 @@ export default {
* @return {Object} The queued song.
*/
set current(song) {
this.state.current = song;
return this.current;
return this.state.current = song;
},
/**
@ -229,6 +227,6 @@ export default {
* @return {Array.<Object>} The shuffled array of song objects
*/
shuffle() {
return (this.all = shuffle(this.all));
return this.all = shuffle(this.all);
},
};

View file

@ -96,11 +96,7 @@ export default {
getLength(songs, toHis) {
const duration = songs.reduce((length, song) => length + song.length, 0);
if (toHis) {
return secondsToHis(duration);
}
return duration;
return toHis ? secondsToHis(duration) : duration;
},
/**
@ -395,7 +391,7 @@ export default {
},
/**
* Called when the application is tore down.
* Called when the application is torn down.
* Reset stuff.
*/
teardown() {

View file

@ -77,9 +77,7 @@ export default {
* @return {Object}
*/
set current(user) {
this.state.current = user;
return this.current;
return this.state.current = user;
},
/**