#Expiring Redux Messages
Send messages to your reducer that will automatically be removed after a provided amount of time.
###Usage
import { applyMiddleware, createStore, combineReducers } from 'redux';
import { sendMessage, messagesMiddleware, messages } from 'expiring-redux-messages';
import baseReducers from './reducers';
const reducers = combineReducers(Object.assign({}, baseReducers, {
messages
});
const initialState = {
,
messages: []
};
const store = createStore(
reducers,
initialState,
applyMiddleware(
messagesMiddleware
)
);
const message = 'I am a temporary message';
store.dispatch(
sendMessage(message, 10000, 1)
);
let currentMessages = store.getState().messages;
currentMessages = store.getState().messages;
currentMessages = store.getState().messages;
##sendMessage
sendMessage
takes three arguments:
- message (string) - the message that should be displayed
- lifetime (int) - the number of milliseconds that the message should last for
- rating (int) - the rating of the message. While not required, a good way to think about the rating is to coincide it with its sign. A rating that is less than 0 is negative, a rating that is greater than 0 is positive, and a rating of 0 is neutral. If you do not provide a rating, it will default to 0.