gab-social/app/javascript/gabsocial/actions/store.js

22 lines
639 B
JavaScript
Raw Normal View History

2020-11-15 18:48:32 +00:00
import { Iterable, fromJS } from 'immutable'
import { hydrateCompose } from './compose'
import { importFetchedAccounts } from './importer'
2019-07-02 08:10:25 +01:00
2020-11-15 18:48:32 +00:00
export const STORE_HYDRATE = 'STORE_HYDRATE'
export const STORE_HYDRATE_LAZY = 'STORE_HYDRATE_LAZY'
2019-07-02 08:10:25 +01:00
2020-11-15 18:48:32 +00:00
const convertState = (rawState) => {
return fromJS(rawState, (k, v) => Iterable.isIndexed(v) ? v.toList() : v.toMap())
}
2019-07-02 08:10:25 +01:00
2020-11-15 18:48:32 +00:00
export const hydrateStore = (rawState) => (dispatch) => {
const state = convertState(rawState)
2019-07-02 08:10:25 +01:00
2020-11-15 18:48:32 +00:00
dispatch({
type: STORE_HYDRATE,
state,
})
2019-07-02 08:10:25 +01:00
2020-11-15 18:48:32 +00:00
dispatch(hydrateCompose())
if (rawState.accounts) dispatch(importFetchedAccounts(Object.values(rawState.accounts)))
}