🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

expiring-redux-messages

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expiring-redux-messages

create messages that will remove themselves

0.3.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

#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';
// dispatch a sendMessage action with a 10 second lifetime
store.dispatch(
  sendMessage(message, 10000, 1)
);

let currentMessages = store.getState().messages;
// currentMessages === []

/*
 * When sendMessage is dispatched, the messagesMiddleware intercepts it
 * and dispatches an addMessage action. That will reach the reducer, which
 * will add the message to the messages array
 */
currentMessages = store.getState().messages;
// currentMessages[0].message === message

/*
 * after ~10 seconds, a removeMessage action will be dispatched, removing
 * the message from the messages array
 */
currentMessages = store.getState().messages;
// currentMessages === []

##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.

Keywords

redux

FAQs

Package last updated on 20 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts