mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-01 01:18:10 +02:00
fix: reset stores on login/logout (#212)
This commit is contained in:
parent
400e8bdb26
commit
7d94f12c04
frontend/src/store
@ -1,5 +1,6 @@
|
||||
import { fromJS, List, Map } from 'immutable';
|
||||
import { RECEIVE_ALL_APPLICATIONS, RECEIVE_APPLICATION } from './actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from '../user/actions';
|
||||
|
||||
function getInitState() {
|
||||
return fromJS({ list: [], apps: {} });
|
||||
@ -11,6 +12,9 @@ const store = (state = getInitState(), action) => {
|
||||
return state.setIn(['apps', action.value.appName], new Map(action.value));
|
||||
case RECEIVE_ALL_APPLICATIONS:
|
||||
return state.set('list', new List(action.value.applications));
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { List, Map as $Map } from 'immutable';
|
||||
import { RECEIVE_ARCHIVE, REVIVE_TOGGLE } from './archive-actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from './user/actions';
|
||||
|
||||
function getInitState() {
|
||||
return new $Map({ list: new List() });
|
||||
@ -11,6 +12,9 @@ const archiveStore = (state = getInitState(), action) => {
|
||||
return state.update('list', list => list.filter(item => item.name !== action.value));
|
||||
case RECEIVE_ARCHIVE:
|
||||
return state.set('list', new List(action.value));
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { fromJS } from 'immutable';
|
||||
import { RECEIVE_CLIENT_INSTANCES } from './client-instance-actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from './user/actions';
|
||||
|
||||
function getInitState() {
|
||||
return fromJS([]);
|
||||
@ -9,6 +10,9 @@ const store = (state = getInitState(), action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_CLIENT_INSTANCES:
|
||||
return fromJS(action.value);
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { List } from 'immutable';
|
||||
import { RECEIVE_CONTEXT, REMOVE_CONTEXT, ADD_CONTEXT_FIELD, UPDATE_CONTEXT_FIELD } from './actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from '../user/actions';
|
||||
|
||||
const DEFAULT_CONTEXT_FIELDS = [{ name: 'environment' }, { name: 'userId' }, { name: 'appName' }];
|
||||
|
||||
@ -19,6 +20,9 @@ const strategies = (state = getInitState(), action) => {
|
||||
const index = state.findIndex(item => item.name === action.context.name);
|
||||
return state.set(index, action.context);
|
||||
}
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
TOGGLE_FEATURE_TOGGLE,
|
||||
} from './feature-actions';
|
||||
|
||||
import { USER_LOGOUT } from './user/actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from './user/actions';
|
||||
|
||||
const features = (state = new List([]), action) => {
|
||||
switch (action.type) {
|
||||
@ -50,6 +50,7 @@ const features = (state = new List([]), action) => {
|
||||
case RECEIVE_FEATURE_TOGGLES:
|
||||
debug(RECEIVE_FEATURE_TOGGLES, action);
|
||||
return new List(action.featureToggles.map($Map));
|
||||
case UPDATE_USER:
|
||||
case USER_LOGOUT:
|
||||
debug(USER_LOGOUT, action);
|
||||
return new List([]);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { List, Map as $Map } from 'immutable';
|
||||
import { RECEIVE_HISTORY, RECEIVE_HISTORY_FOR_TOGGLE } from './history-actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from './user/actions';
|
||||
|
||||
function getInitState() {
|
||||
return new $Map({ list: new List(), toggles: new $Map() });
|
||||
@ -11,6 +12,9 @@ const historyStore = (state = getInitState(), action) => {
|
||||
return state.setIn(['toggles', action.value.toggleName], new List(action.value.events));
|
||||
case RECEIVE_HISTORY:
|
||||
return state.set('list', new List(action.value));
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Map as $Map, List, fromJS } from 'immutable';
|
||||
import actions from './input-actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from './user/actions';
|
||||
|
||||
function getInitState() {
|
||||
return new $Map();
|
||||
@ -101,6 +102,9 @@ const inputState = (state = getInitState(), action) => {
|
||||
return updateInList(state, action);
|
||||
case actions.CLEAR:
|
||||
return clear(state, action);
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
// console.log('TYPE', action.type, action);
|
||||
return state;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { fromJS, Map as $Map } from 'immutable';
|
||||
import { UPDATE_SETTING } from './actions';
|
||||
import { USER_LOGOUT, UPDATE_USER } from '../user/actions';
|
||||
|
||||
// TODO: provde a mock if localstorage does not exists?
|
||||
const localStorage = window.localStorage || {};
|
||||
@ -25,6 +26,9 @@ const settingStore = (state = getInitState(), action) => {
|
||||
switch (action.type) {
|
||||
case UPDATE_SETTING:
|
||||
return updateSetting(state, action);
|
||||
case USER_LOGOUT:
|
||||
case UPDATE_USER:
|
||||
return getInitState();
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user