1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/stores/user_store.js

50 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
import { altUser } from '../alt';
2015-06-03 11:49:39 +02:00
import UserActions from '../actions/user_actions';
2015-05-20 16:19:40 +02:00
import UserSource from '../sources/user_source';
2015-05-20 16:44:45 +02:00
2015-10-29 17:15:26 +01:00
class UserStore {
2015-05-20 16:19:40 +02:00
constructor() {
2015-06-01 18:59:47 +02:00
this.currentUser = {};
this.userMeta = {
invalidateCache: false,
err: null
};
2015-06-03 11:49:39 +02:00
this.bindActions(UserActions);
this.registerAsync(UserSource);
2015-05-20 16:19:40 +02:00
}
onFetchCurrentUser(invalidateCache) {
this.userMeta.invalidateCache = invalidateCache;
if(!this.getInstance().isLoading()) {
this.getInstance().lookupCurrentUser();
}
2015-05-20 16:19:40 +02:00
}
onSuccessFetchCurrentUser({users: [user = {}]}) {
this.userMeta.invalidateCache = false;
2015-11-16 17:44:56 +01:00
this.userMeta.err = null;
this.currentUser = user;
}
onLogoutCurrentUser() {
this.getInstance().performLogoutCurrentUser();
}
onSuccessLogoutCurrentUser() {
2015-06-20 16:43:18 +02:00
this.currentUser = {};
}
onErrorCurrentUser(err) {
console.logGlobal(err);
this.userMeta.err = err;
}
2015-06-01 18:59:47 +02:00
}
2015-05-20 16:19:40 +02:00
export default altUser.createStore(UserStore, 'UserStore');