Last active
August 23, 2019 18:15
-
-
Save ryan2clw/d56d24eafe9cfcc833a92ed47ca48adf to your computer and use it in GitHub Desktop.
Action types for python bingo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { action as act } from 'typesafe-actions' | |
import actionTypes from './actionTypes'; | |
import { Reducer } from 'redux' | |
/* Message Actions */ | |
export const success = (message: string) => act(actionTypes.ALERT_SUCCESS, message); | |
export const danger = (message: string) => act(actionTypes.ALERT_DANGER, message) | |
export const clear = () => act(actionTypes.ALERT_CLEAR); | |
export interface IMessageState { | |
readonly type: string, | |
readonly message: string | |
} | |
const initialState = { | |
message: "", | |
type: "alert-clear", | |
} | |
/* Message Reducer */ | |
const messageReducer: Reducer<IMessageState> = (state = initialState, action) => { | |
switch (action.type) { | |
case actionTypes.ALERT_SUCCESS: | |
return { | |
message: action.payload, | |
type: 'alert-success', | |
}; | |
case actionTypes.ALERT_DANGER: | |
return { | |
message: action.payload, | |
type: 'alert-danger', | |
}; | |
case actionTypes.ALERT_CLEAR: | |
return { | |
message: action.payload, | |
type: 'alert-clear', | |
}; | |
default: | |
return state | |
} | |
} | |
export { messageReducer } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment