Optimize some code

This commit is contained in:
An Phan 2016-05-03 11:08:24 +07:00
parent 5e45f4cb4d
commit 2aa45bce03
6 changed files with 22 additions and 91 deletions

View file

@ -50,11 +50,7 @@ export default {
this.remove(song);
}
http.post('interaction/like', { song: song.id }, () => {
if (cb) {
cb();
}
});
http.post('interaction/like', { song: song.id }, () => cb && cb());
},
/**
@ -94,11 +90,7 @@ export default {
each(songs, song => song.liked = true);
this.add(songs);
http.post('interaction/batch/like', { songs: map(songs, 'id') }, () => {
if (cb) {
cb();
}
});
http.post('interaction/batch/like', { songs: map(songs, 'id') }, () => cb && cb());
},
/**
@ -108,15 +100,9 @@ export default {
* @param {?Function} cb
*/
unlike(songs, cb = null) {
// Don't wait for the HTTP response to update the status, just set them to Unliked right away.
// This may cause a minor problem if the request fails somehow, but do we care?
each(songs, song => song.liked = false);
this.remove(songs);
http.post('interaction/batch/unlike', { songs: map(songs, 'id') }, () => {
if (cb) {
cb();
}
});
http.post('interaction/batch/unlike', { songs: map(songs, 'id') }, () => cb && cb());
},
};

View file

@ -89,9 +89,7 @@ export default {
this.getSongs(playlist);
this.add(playlist);
if (cb) {
cb();
}
cb && cb();
});
},
@ -106,10 +104,7 @@ export default {
http.delete(`playlist/${playlist.id}`, {}, () => {
this.remove(playlist);
if (cb) {
cb();
}
cb && cb();
});
},
@ -128,11 +123,7 @@ export default {
return;
}
http.put(`playlist/${playlist.id}/sync`, { songs: map(playlist.songs, 'id') }, () => {
if (cb) {
cb();
}
});
http.put(`playlist/${playlist.id}/sync`, { songs: map(playlist.songs, 'id') }, () => cb && cb());
},
/**
@ -145,11 +136,7 @@ export default {
removeSongs(playlist, songs, cb = null) {
playlist.songs = difference(playlist.songs, songs);
http.put(`playlist/${playlist.id}/sync`, { songs: map(playlist.songs, 'id') }, () => {
if (cb) {
cb();
}
});
http.put(`playlist/${playlist.id}/sync`, { songs: map(playlist.songs, 'id') }, () => cb && cb());
},
/**
@ -161,10 +148,6 @@ export default {
update(playlist, cb = null) {
NProgress.start();
http.put(`playlist/${playlist.id}`, { name: playlist.name }, () => {
if (cb) {
cb();
}
});
http.put(`playlist/${playlist.id}`, { name: playlist.name }, () => cb && cb());
},
};

View file

@ -157,10 +157,7 @@ export default {
clear(cb = null) {
this.all = [];
this.current = null;
if (cb) {
cb();
}
cb && cb();
},
/**

View file

@ -50,9 +50,7 @@ export default {
window.useLastfm = this.state.useLastfm = data.useLastfm;
if (successCb) {
successCb();
}
successCb && successCb();
}, errorCb);
},

View file

@ -158,9 +158,7 @@ export default {
song.album.playCount += song.playCount - oldCount;
song.album.artist.playCount += song.playCount - oldCount;
if (cb) {
cb();
}
cb && cb();
});
},
@ -186,9 +184,7 @@ export default {
getInfo(song, cb = null) {
// Check if the song's info has been retrieved before.
if (song.infoRetrieved) {
if (cb) {
cb();
}
cb && cb();
return;
}
@ -229,9 +225,7 @@ export default {
song.infoRetrieved = true;
if (cb) {
cb();
}
cb && cb();
});
},
@ -246,11 +240,7 @@ export default {
return;
}
http.post(`${song.id}/scrobble/${song.playStartTime}`, () => {
if (cb) {
cb();
}
});
http.post(`${song.id}/scrobble/${song.playStartTime}`, () => cb && cb());
},
/**
@ -272,14 +262,8 @@ export default {
}, response => {
each(response.data, song => this.syncUpdatedSong(song));
if (successCb) {
successCb();
}
}, () => {
if (errorCb) {
errorCb();
}
});
successCb && successCb();
}, () => errorCb && errorCb());
},
/**

View file

@ -105,11 +105,7 @@ export default {
*/
login(email, password, successCb = null, errorCb = null) {
NProgress.start();
http.post('me', { email, password }, () => {
if (successCb) {
successCb();
}
}, errorCb);
http.post('me', { email, password }, () => successCb && successCb(), errorCb);
},
/**
@ -118,11 +114,7 @@ export default {
* @param {Function} cb The callback.
*/
logout(cb = null) {
http.delete('me', {}, () => {
if (cb) {
cb();
}
});
http.delete('me', {}, () => cb && cb());
},
/**
@ -141,10 +133,7 @@ export default {
email: this.current.email
}, () => {
this.setAvatar();
if (cb) {
cb();
}
cb && cb();
}
);
},
@ -166,9 +155,7 @@ export default {
this.setAvatar(user);
this.all.unshift(user);
if (cb) {
cb();
}
cb && cb();
});
},
@ -188,9 +175,7 @@ export default {
this.setAvatar(user);
user.password = '';
if (cb) {
cb();
}
cb && cb();
});
},
@ -228,9 +213,7 @@ export default {
/**
* Brian May enters the stage.
*/
if (cb) {
cb();
}
cb && cb();
});
},
};