Use the same .reset as RoomViewStore

This commit is contained in:
Luke Barnard 2017-05-26 17:23:02 +01:00
parent 263a51938d
commit 9311b9012a
2 changed files with 20 additions and 12 deletions

View file

@ -16,6 +16,10 @@ limitations under the License.
import dis from '../dispatcher'; import dis from '../dispatcher';
import {Store} from 'flux/utils'; import {Store} from 'flux/utils';
const INITIAL_STATE = {
deferred_action: null,
};
/** /**
* A class for storing application state to do with login/registration. This is a simple * A class for storing application state to do with login/registration. This is a simple
* flux store that listens for actions and updates its state accordingly, informing any * flux store that listens for actions and updates its state accordingly, informing any
@ -33,9 +37,7 @@ class LifecycleStore extends Store {
super(dis); super(dis);
// Initialise state // Initialise state
this._state = { this._state = INITIAL_STATE;
deferred_action: null,
};
} }
_setState(newState) { _setState(newState) {
@ -62,12 +64,14 @@ class LifecycleStore extends Store {
dis.dispatch(deferredAction); dis.dispatch(deferredAction);
break; break;
case 'on_logged_out': case 'on_logged_out':
this._state = { this.reset();
deferred_action: null,
};
break; break;
} }
} }
reset() {
this._state = Object.assign({}, INITIAL_STATE);
}
} }
let singletonLifecycleStore = null; let singletonLifecycleStore = null;

View file

@ -16,6 +16,10 @@ limitations under the License.
import dis from '../dispatcher'; import dis from '../dispatcher';
import {Store} from 'flux/utils'; import {Store} from 'flux/utils';
const INITIAL_STATE = {
cachedPassword: localStorage.getItem('mx_pass'),
};
/** /**
* A class for storing application state to do with the session. This is a simple flux * A class for storing application state to do with the session. This is a simple flux
* store that listens for actions and updates its state accordingly, informing any * store that listens for actions and updates its state accordingly, informing any
@ -33,9 +37,7 @@ class SessionStore extends Store {
super(dis); super(dis);
// Initialise state // Initialise state
this._state = { this._state = INITIAL_STATE;
cachedPassword: localStorage.getItem('mx_pass'),
};
} }
_update() { _update() {
@ -67,11 +69,13 @@ class SessionStore extends Store {
}); });
break; break;
case 'on_logged_out': case 'on_logged_out':
this._state = { this.reset();
cachedPassword: null,
};
break; break;
} }
reset() {
this._state = Object.assign({}, INITIAL_STATE);
}
} }
getCachedPassword() { getCachedPassword() {