fix(Flash): Minize flash state
This commit is contained in:
@ -14,7 +14,7 @@ export const alertTypes = _.keyBy(_.identity)([
|
|||||||
'warning',
|
'warning',
|
||||||
'danger'
|
'danger'
|
||||||
]);
|
]);
|
||||||
export const normalizeAlertType = _.get(alertTypes, 'info');
|
export const normalizeAlertType = alertType => alertTypes[alertType] || 'info';
|
||||||
|
|
||||||
export const getFlashAction = _.flow(
|
export const getFlashAction = _.flow(
|
||||||
_.property('meta'),
|
_.property('meta'),
|
||||||
@ -42,15 +42,12 @@ export const expressToStack = _.flow(
|
|||||||
})))
|
})))
|
||||||
);
|
);
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = [];
|
||||||
stack: [{ alertType: 'danger', message: 'foo nar' }]
|
|
||||||
};
|
|
||||||
|
|
||||||
const getNS = _.property(ns);
|
const getNS = _.property(ns);
|
||||||
|
|
||||||
export const latestMessageSelector = _.flow(
|
export const latestMessageSelector = _.flow(
|
||||||
getNS,
|
getNS,
|
||||||
_.property('stack'),
|
|
||||||
_.head,
|
_.head,
|
||||||
_.defaultTo({})
|
_.defaultTo({})
|
||||||
);
|
);
|
||||||
@ -59,30 +56,24 @@ export default composeReducers(
|
|||||||
ns,
|
ns,
|
||||||
handleActions(
|
handleActions(
|
||||||
() => ({
|
() => ({
|
||||||
[types.clickOnClose]: (state) => ({
|
[types.clickOnClose]: _.tail,
|
||||||
|
[types.messagesFoundOnBoot]: (state, { payload }) => [
|
||||||
...state,
|
...state,
|
||||||
stack: _.tail(state.stack)
|
...expressToStack(payload)
|
||||||
}),
|
]
|
||||||
[types.messagesFoundOnBoot]: (state, { payload }) => ({
|
|
||||||
...state,
|
|
||||||
stack: [...state.stack, ...expressToStack(payload)]
|
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
defaultState,
|
defaultState,
|
||||||
),
|
),
|
||||||
function metaReducer(state = defaultState, action) {
|
function metaReducer(state = defaultState, action) {
|
||||||
if (isFlashAction(action)) {
|
if (isFlashAction(action)) {
|
||||||
const { payload: { alertType, message } } = getFlashAction(action);
|
const { payload: { alertType, message } } = getFlashAction(action);
|
||||||
return {
|
return [
|
||||||
...state,
|
...state,
|
||||||
stack: [
|
|
||||||
...state.stack,
|
|
||||||
{
|
{
|
||||||
alertType: normalizeAlertType(alertType),
|
alertType: normalizeAlertType(alertType),
|
||||||
message: _.escape(message)
|
message: _.escape(message)
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user