1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 00:28:00 +02: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() { componentDidUpdate() {
this.redirectConditionally(); // Only refresh this component, when UserSources are not loading
// data from the server
if(!UserStore.isLoading()) {
this.redirectConditionally();
}
}, },
componentWillUnmount() { componentWillUnmount() {

View File

@ -27,7 +27,7 @@ let AccountSettings = React.createClass({
}, },
handleSuccess(){ handleSuccess(){
this.props.loadUser(); this.props.loadUser(true);
let notification = new GlobalNotificationModel(getLangText('Settings succesfully updated'), 'success', 5000); let notification = new GlobalNotificationModel(getLangText('Settings succesfully updated'), 'success', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
}, },

View File

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

View File

@ -11,13 +11,13 @@ const UserSource = {
}, },
local(state) { local(state) {
return state.currentUser && state.currentUser.email ? state.currentUser : {}; return state.currentUser && state.currentUser.email ? state : {};
}, },
success: UserActions.receiveCurrentUser, success: UserActions.receiveCurrentUser,
shouldFetch(state) { 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 { class UserStore {
constructor() { constructor() {
this.currentUser = {}; this.currentUser = {};
this.invalidateCache = false;
this.bindActions(UserActions); this.bindActions(UserActions);
this.registerAsync(UserSource); this.registerAsync(UserSource);
} }
onFetchCurrentUser() { onFetchCurrentUser(invalidateCache) {
this.invalidateCache = invalidateCache;
if(!this.getInstance().isLoading()) { if(!this.getInstance().isLoading()) {
this.getInstance().fetchUser(); this.getInstance().fetchUser();
} }
} }
onReceiveCurrentUser({users: [user]}) { onReceiveCurrentUser({users: [user]}) {
this.invalidateCache = false;
this.currentUser = user; this.currentUser = user;
} }