Parse the Redux state as an Immutable.Record
This commit is contained in:
parent
2ff3643368
commit
90afa8aeaf
2 changed files with 27 additions and 5 deletions
12
app/soapbox/reducers/__tests__/index-test.js
Normal file
12
app/soapbox/reducers/__tests__/index-test.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { Record as ImmutableRecord } from 'immutable';
|
||||
|
||||
import reducer from '..';
|
||||
|
||||
describe('root reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
const result = reducer(undefined, {});
|
||||
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
||||
expect(result.accounts.get('')).toBe(undefined);
|
||||
expect(result.instance.get('version')).toEqual('0.0.0');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Record as ImmutableRecord } from 'immutable';
|
||||
import { combineReducers } from 'redux-immutable';
|
||||
|
||||
import { AUTH_LOGGED_OUT } from 'soapbox/actions/auth';
|
||||
|
@ -58,7 +58,7 @@ import timelines from './timelines';
|
|||
import trends from './trends';
|
||||
import user_lists from './user_lists';
|
||||
|
||||
const appReducer = combineReducers({
|
||||
const reducers = {
|
||||
dropdown_menu,
|
||||
timelines,
|
||||
meta,
|
||||
|
@ -113,13 +113,23 @@ const appReducer = combineReducers({
|
|||
pending_statuses,
|
||||
aliases,
|
||||
accounts_meta,
|
||||
});
|
||||
};
|
||||
|
||||
// Build a default state from all reducers: it has the key and `undefined`
|
||||
const StateRecord = ImmutableRecord(
|
||||
Object.keys(reducers).reduce((params, reducer) => {
|
||||
params[reducer] = undefined;
|
||||
return params;
|
||||
}, {}),
|
||||
);
|
||||
|
||||
const appReducer = combineReducers(reducers, StateRecord);
|
||||
|
||||
// Clear the state (mostly) when the user logs out
|
||||
const logOut = (state = ImmutableMap()) => {
|
||||
const logOut = (state = StateRecord()) => {
|
||||
const whitelist = ['instance', 'soapbox', 'custom_emojis', 'auth'];
|
||||
|
||||
return ImmutableMap(
|
||||
return StateRecord(
|
||||
whitelist.reduce((acc, curr) => {
|
||||
acc[curr] = state.get(curr);
|
||||
return acc;
|
||||
|
|
Loading…
Reference in a new issue