Created
July 18, 2018 08:15
-
-
Save YozhEzhi/6f15270512ac36437f7da9d6bbd77e77 to your computer and use it in GitHub Desktop.
Заметки по React.
This file contains hidden or 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
| /** | |
| * Пример отмены промиса (race conditions). | |
| * Например, при переключении закладок - выполняется подгрузка данных. | |
| * При клике на вторую вкладку, а потом сразу на первую - запрос по первой вкладке | |
| * всё ещё будет обрабатываться. Обработку уже ненужного запроса - можно прервать. | |
| */ | |
| export const fetchTodos = (filter) => (dispatch, getState) => { | |
| if (getIsFetching(getState(), filter)) { | |
| return Promise.resolve(); | |
| } | |
| dispatch(requestTodos(filter)); | |
| return api.fetchTodos(filter).then(response => { | |
| dispatch(receiveTodos(filter, response)); | |
| }); | |
| }; | |
| /** | |
| * mapDispatchToProps сокращение. | |
| */ | |
| // Вместо: | |
| const mapDispatchToProps = (dispatch) => ({ | |
| onTodoClick(id) { | |
| dispatch(toggleTodo(id)); | |
| }, | |
| }); | |
| const VisibleTodoList = withRouter(connect( | |
| mapStateToProps, | |
| mapDispatchToProps | |
| )(TodoList)); | |
| // Можно написать вот так: | |
| const VisibleTodoList = withRouter(connect( | |
| mapStateToProps, | |
| {onTodoClick: toggleTodo}, | |
| )(TodoList)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment