koel/resources/assets/js/stores/shared.js

34 lines
750 B
JavaScript
Raw Normal View History

2015-12-13 04:42:28 +00:00
import http from '../services/http';
2015-12-20 12:17:35 +00:00
import { assign } from 'lodash';
2015-12-13 04:42:28 +00:00
export default {
state: {
songs: [],
albums: [],
artists: [],
favorites: [],
queued: [],
interactions: [],
users: [],
settings: [],
currentUser: null,
playlists: [],
2015-12-20 12:17:35 +00:00
useLastfm: false,
2015-12-13 04:42:28 +00:00
},
init(cb = null) {
http.get('data', {}, data => {
2015-12-20 12:17:35 +00:00
assign(this.state, data);
// If this is a new user, initialize his preferences to be an empty object.
if (!this.state.currentUser.preferences) {
this.state.currentUser.preferences = {};
}
2015-12-13 04:42:28 +00:00
if (cb) {
cb();
}
});
},
};