-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor waitForStoreChange to use assertion callback
BREAKING CHANGE: The method waitForStoreChange now uses an assertion callback as first parameter. The callback's argument is the current state. And you can perform any assertions with it.
- Loading branch information
Showing
19 changed files
with
130 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import { connect } from "react-redux"; | ||
|
||
import { toggleTodo, VisibilityFilters } from "../actions"; | ||
import TodoList, { StateProps, DispatchProps, OwnProps, TodoItem } from "../components/TodoList"; | ||
import { toggleTodo } from "../actions"; | ||
import TodoList, { DispatchProps, OwnProps, StateProps } from "../components/TodoList"; | ||
import { TodoItem, VisibilityFilter } from "../reducers"; | ||
import * as TodoSelectors from "../selectors"; | ||
|
||
const getVisibleTodos = (todos: TodoItem[], filter: string) => { | ||
const getVisibleTodos = (todos: TodoItem[], filter: VisibilityFilter) => { | ||
switch (filter) { | ||
case VisibilityFilters.SHOW_ALL: | ||
case "SHOW_ALL": | ||
return todos; | ||
case VisibilityFilters.SHOW_COMPLETED: | ||
case "SHOW_COMPLETED": | ||
return todos.filter(t => t.completed); | ||
case VisibilityFilters.SHOW_ACTIVE: | ||
case "SHOW_ACTIVE": | ||
return todos.filter(t => !t.completed); | ||
default: | ||
throw new Error("Unknown filter: " + filter); | ||
} | ||
}; | ||
|
||
export default connect<StateProps, DispatchProps, OwnProps>( | ||
(state: any) => ({ | ||
todos: getVisibleTodos(state.todos, state.visibilityFilter) | ||
}), | ||
dispatch => ({ | ||
toggleTodo: id => dispatch(toggleTodo(id)) | ||
}) | ||
function mapStateToProps(state, ownProps) { | ||
const todos = TodoSelectors.getTodos(state); | ||
const visibilityFilter = TodoSelectors.getVisibilityFilter(state); | ||
return { | ||
todos: getVisibleTodos(todos, visibilityFilter) | ||
}; | ||
}, | ||
function mapDispatchToProps(dispatch, ownProps): DispatchProps { | ||
return { | ||
toggleTodo: id => dispatch(toggleTodo(id)) | ||
}; | ||
} | ||
)(TodoList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { combineReducers } from "redux"; | ||
|
||
import todos from "./todos"; | ||
import visibilityFilter from "./visibilityFilter"; | ||
import todos, { TodoItem } from "./todos"; | ||
import visibilityFilter, { VisibilityFilter } from "./visibilityFilter"; | ||
|
||
export default combineReducers({ | ||
todos, | ||
visibilityFilter | ||
}); | ||
|
||
export { TodoItem, VisibilityFilter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createSelector } from "reselect"; | ||
|
||
import { TodoItem, VisibilityFilter } from "../reducers"; | ||
|
||
export function getVisibilityFilter(state: any): VisibilityFilter { | ||
return state.visibilityFilter; | ||
} | ||
|
||
export function getTodos(state: any): TodoItem[] { | ||
return state.todos; | ||
} | ||
|
||
export const getVisibleTodos = createSelector( | ||
[getVisibilityFilter, getTodos], | ||
(visibilityFilter, todos) => { | ||
switch (visibilityFilter) { | ||
case "SHOW_ALL": | ||
return todos; | ||
case "SHOW_COMPLETED": | ||
return todos.filter(t => t.completed); | ||
case "SHOW_ACTIVE": | ||
return todos.filter(t => !t.completed); | ||
} | ||
} | ||
); |
Oops, something went wrong.