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