1
0
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:
Tim Daubenschütz 2015-11-02 11:31:02 +01:00
parent d50aa2913f
commit 0770a1ed61
5 changed files with 16 additions and 7 deletions

View File

@ -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() {

View File

@ -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);
},

View File

@ -46,8 +46,8 @@ let SettingsContainer = React.createClass({
UserStore.unlisten(this.onChange);
},
loadUser(){
UserActions.fetchCurrentUser();
loadUser(invalidateCache){
UserActions.fetchCurrentUser(invalidateCache);
},
onChange(state) {

View File

@ -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;
}
}
};

View File

@ -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;
}