mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Implement cache invalidation functionality for UserStore & UserSources
This commit is contained in:
parent
d50aa2913f
commit
0770a1ed61
@ -47,7 +47,11 @@ export default function AuthProxyHandler({to, when}) {
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
this.redirectConditionally();
|
||||
// Only refresh this component, when UserSources are not loading
|
||||
// data from the server
|
||||
if(!UserStore.isLoading()) {
|
||||
this.redirectConditionally();
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -27,7 +27,7 @@ let AccountSettings = React.createClass({
|
||||
},
|
||||
|
||||
handleSuccess(){
|
||||
this.props.loadUser();
|
||||
this.props.loadUser(true);
|
||||
let notification = new GlobalNotificationModel(getLangText('Settings succesfully updated'), 'success', 5000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
},
|
||||
|
@ -46,8 +46,8 @@ let SettingsContainer = React.createClass({
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
loadUser(){
|
||||
UserActions.fetchCurrentUser();
|
||||
loadUser(invalidateCache){
|
||||
UserActions.fetchCurrentUser(invalidateCache);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
|
@ -11,13 +11,13 @@ const UserSource = {
|
||||
},
|
||||
|
||||
local(state) {
|
||||
return state.currentUser && state.currentUser.email ? state.currentUser : {};
|
||||
return state.currentUser && state.currentUser.email ? state : {};
|
||||
},
|
||||
|
||||
success: UserActions.receiveCurrentUser,
|
||||
|
||||
shouldFetch(state) {
|
||||
return state.currentUser && !state.currentUser.email;
|
||||
return state.invalidateCache || state.currentUser && !state.currentUser.email;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -9,17 +9,22 @@ import UserSource from '../sources/user_source';
|
||||
class UserStore {
|
||||
constructor() {
|
||||
this.currentUser = {};
|
||||
this.invalidateCache = false;
|
||||
|
||||
this.bindActions(UserActions);
|
||||
this.registerAsync(UserSource);
|
||||
}
|
||||
|
||||
onFetchCurrentUser() {
|
||||
onFetchCurrentUser(invalidateCache) {
|
||||
this.invalidateCache = invalidateCache;
|
||||
|
||||
if(!this.getInstance().isLoading()) {
|
||||
this.getInstance().fetchUser();
|
||||
}
|
||||
}
|
||||
|
||||
onReceiveCurrentUser({users: [user]}) {
|
||||
this.invalidateCache = false;
|
||||
this.currentUser = user;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user