Skip to content

Commit

Permalink
support in distinct state
Browse files Browse the repository at this point in the history
  • Loading branch information
ntedgi committed May 8, 2019
1 parent 99db13f commit e3f24f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 12 additions & 7 deletions examples/todos-with-undo/src/containers/UndoRedo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ let UndoRedo = ({ canUndo, canRedo, onUndo, onRedo }) => (
</button>
</p>
)
const mapStateToProps = (state) => ({

const mapStateToProps = state => {
return {
canUndo: state.todos.present.length > 0,
canRedo: state.todos.history.length > 0
})
}
}

const mapDispatchToProps = dispatch => {
return {
onUndo: () => dispatch(UndoActionCreators.undo()),
onRedo: () => dispatch(UndoActionCreators.redo())
}
}

const mapDispatchToProps = ({
onUndo: UndoActionCreators.undo,
onRedo: UndoActionCreators.redo
})
UndoRedo = connect(
mapStateToProps,
mapDispatchToProps
)(UndoRedo)

export default UndoRedo
export default UndoRedo
8 changes: 5 additions & 3 deletions examples/todos-with-undo/src/reducers/todos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import undoable, { includeAction } from 'redux-undo'
import undoable, { distinctState } from 'redux-undo'

const todo = (state, action) => {
switch (action.type) {
Expand All @@ -25,6 +25,7 @@ const todo = (state, action) => {
const todos = (state = [], action) => {
switch (action.type) {
case 'ADD_TODO':

return [
...state,
todo(undefined, action)
Expand All @@ -38,6 +39,7 @@ const todos = (state = [], action) => {
}
}

const undoableTodos = undoable(todos )

const undoableTodos = undoable(todos, {
filter: distinctState()
})
export default undoableTodos

0 comments on commit e3f24f9

Please sign in to comment.