mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-28 11:00:26 -05:00
[Glitch] Use an Immutable Record as the root state
Port 78ba12f0bf
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
2ba4773ebe
commit
eb1cb8224a
@ -1,3 +1,5 @@
|
|||||||
|
import { Record as ImmutableRecord } from 'immutable';
|
||||||
|
|
||||||
import { loadingBarReducer } from 'react-redux-loading-bar';
|
import { loadingBarReducer } from 'react-redux-loading-bar';
|
||||||
import { combineReducers } from 'redux-immutable';
|
import { combineReducers } from 'redux-immutable';
|
||||||
|
|
||||||
@ -92,6 +94,22 @@ const reducers = {
|
|||||||
followed_tags,
|
followed_tags,
|
||||||
};
|
};
|
||||||
|
|
||||||
const rootReducer = combineReducers(reducers);
|
// We want the root state to be an ImmutableRecord, which is an object with a defined list of keys,
|
||||||
|
// so it is properly typed and keys can be accessed using `state.<key>` syntax.
|
||||||
|
// This will allow an easy conversion to a plain object once we no longer call `get` or `getIn` on the root state
|
||||||
|
|
||||||
|
// By default with `combineReducers` it is a Collection, so we provide our own implementation to get a Record
|
||||||
|
const initialRootState = Object.fromEntries(
|
||||||
|
Object.entries(reducers).map(([name, reducer]) => [
|
||||||
|
name,
|
||||||
|
reducer(undefined, {
|
||||||
|
// empty action
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
const RootStateRecord = ImmutableRecord(initialRootState, 'RootState');
|
||||||
|
|
||||||
|
const rootReducer = combineReducers(reducers, RootStateRecord);
|
||||||
|
|
||||||
export { rootReducer };
|
export { rootReducer };
|
||||||
|
Loading…
Reference in New Issue
Block a user