flash-redux
v0.0.2
Published
Flash messages for redux applications
Downloads
1
Readme
flash-redux
Redux middleware, actions and reducer for managing flash messages.
Based on rails flash etc.
Install
npm install flash-redux --save
How it works
flashNow
andflashNext
action creators allow you to add newFlash
objects to your redux store via theflashReducer
.clearFlash
action creator allows you to clear thenow
array.flashMiddleware
watches for a configurable trigger action (e.g.react-router-redux
'sLOCATION_CHANGE
') and cycles the flash messages, sonext
becomesnow
, andnext
gets reset to an empty array.
How you display the messages is up to you!
API
new Flash(message, [type = 'message'])
constructor functionFlash
objects have key
, message
and type
properties.
key
is a unique identifier generated byuuid
.message
: Stringtype
: 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.