Skip to content

Commit

Permalink
feat(getState): add ability to find state
Browse files Browse the repository at this point in the history
Currently, this lib expects the state to be at the key `toastr` (and even handles when the state object is an immutable object (via `state.get`). There is no way to define a custom / different location easily.

This adds an optional prop to the `ReduxToastr` component which is a function that takes the current state to provide the toastr state.
  • Loading branch information
TheSharpieOne authored and diegoddox committed Oct 4, 2019
1 parent 6e84797 commit 03419d4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import ReduxToastr from 'react-redux-toastr'
newestOnTop={false}
preventDuplicates
position="top-left"
getState={(state) => state.toastr} // This is the default
transitionIn="fadeIn"
transitionOut="fadeOut"
progressBar
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-toastr",
"version": "7.5.2",
"version": "7.6.0",
"description": "react-redux-toastr is a React toastr message implemented with Redux",
"main": "lib/index.js",
"jsnext:main": "./src/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/ReduxToastr.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class ReduxToastr extends React.Component {
transitionOut: TRANSITIONS.out[0],
preventDuplicates: false,
closeOnToastrClick: false,
getState: (state) => state.toastr,

This comment has been minimized.

Copy link
@TheSharpieOne

TheSharpieOne Nov 5, 2019

Author Contributor

This technically became a breaking change since this default implementation doesn't match the existing implementation since it doesn't account for state.get('toastr') like it previously did.
It requires anyone depending on state.get('toastr') to override getState with state => state.get('toastr').

This comment has been minimized.

Copy link
@diegoddox

diegoddox Nov 6, 2019

Owner

True, I've made the mistake of not pumping as a breaking change.

confirmOptions: {
okText: 'ok',
cancelText: 'cancel'
Expand Down Expand Up @@ -155,8 +156,8 @@ export class ReduxToastr extends React.Component {
}

export default connect(
state => ({
toastr: state.toastr ? state.toastr : state.get('toastr')
(state, ownProps) => ({
toastr: ownProps.getState(state),
}),
actions
)(ReduxToastr);

0 comments on commit 03419d4

Please sign in to comment.