koel/resources/assets/js/stores/preference.js

44 lines
845 B
JavaScript
Raw Normal View History

2015-12-13 04:42:28 +00:00
import _ from 'lodash';
import userStore from './user';
import ls from '../services/ls';
export default {
storeKey: '',
state: {
volume: 7,
notify: true,
repeatMode: 'NO_REPEAT',
showExtraPanel: true,
},
/**
* Init the store
* @param object user The user whose preferences we are managing.
*/
init(user = null) {
if (!user) {
user = userStore.current();
}
this.storeKey = `preferences_${user.id}`;
_.extend(this.state, ls.get(this.storeKey, this.state));
},
set(key, val) {
this.state[key] = val;
this.save();
},
get(key) {
var val = _.has(this.state, key) ? this.state[key] : null;
return val;
},
save() {
ls.set(this.storeKey, this.state);
},
};