Skip to content

harrim91/flash-redux

Repository files navigation

flash-redux

Build Status Coverage Status

Redux middleware, actions and reducer for managing flash messages.

Based on rails flash etc.

Install

npm install flash-redux --save

How it works

  • flashNow and flashNext action creators allow you to add new Flash objects to your redux store via the flashReducer.
  • clearFlash action creator allows you to clear the now array.
  • flashMiddleware watches for a configurable trigger action (e.g. react-router-redux's LOCATION_CHANGE') and cycles the flash messages, so next becomes now, and next gets reset to an empty array.

How you display the messages is up to you!

API

new Flash(message, [type = 'message'])

constructor function
Flash objects have key, message and type properties.

  • key is a unique identifier generated by uuid.
  • message: String
  • type: String : default = 'message'

flashReducer

A reducer function that stores flash messages in now and next keys

flashMiddleware({ cycle })

Redux middleware that captures an action type and cycles the flashReducer keys, causing next to become now and next gets reset to an empty array.
The config object should contain a cycle key with a value of the action type to trigger the cycle event.
Typically this would be something like react-router-redux's LOCATION_CHANGE'.

flashNow(message, [messageType])

Action creator that adds a Flash object to the now array.

flashNext(message, [messageType])

Action creator that adds a Flash object to the next array.

clearFlash()

Action creator that clears the now array.

About

Flash messages for redux applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published