You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
// ------------------------------------
|
|
// Initial State
|
|
// ------------------------------------
|
|
const initialState = {
|
|
isLoading: true,
|
|
isMounted: false
|
|
}
|
|
|
|
// ------------------------------------
|
|
// Constants
|
|
// ------------------------------------
|
|
export const SET_LOADING = 'SET_LOADING'
|
|
export const SET_MOUNTED = 'SET_MOUNTED'
|
|
|
|
// ------------------------------------
|
|
// Actions
|
|
// ------------------------------------
|
|
export function setLoading(isLoading) {
|
|
return {
|
|
type: SET_LOADING,
|
|
isLoading
|
|
}
|
|
}
|
|
|
|
export function setMounted(isMounted) {
|
|
return {
|
|
type: SET_MOUNTED,
|
|
isMounted
|
|
}
|
|
}
|
|
|
|
// ------------------------------------
|
|
// Action Handlers
|
|
// ------------------------------------
|
|
const ACTION_HANDLERS = {
|
|
[SET_LOADING]: (state, { isLoading }) => ({ ...state, isLoading }),
|
|
[SET_MOUNTED]: (state, { isMounted }) => ({ ...state, isMounted })
|
|
}
|
|
|
|
// ------------------------------------
|
|
// Selectors
|
|
// ------------------------------------
|
|
|
|
const loadingSelectors = {}
|
|
loadingSelectors.isLoading = state => state.loading.isLoading
|
|
loadingSelectors.isMounted = state => state.loading.isMounted
|
|
|
|
export { loadingSelectors }
|
|
|
|
// ------------------------------------
|
|
// Reducer
|
|
// ------------------------------------
|
|
export default function loadingReducer(state = initialState, action) {
|
|
const handler = ACTION_HANDLERS[action.type]
|
|
|
|
return handler ? handler(state, action) : state
|
|
}
|
|
|