Created
December 1, 2015 08:53
-
-
Save b2whats/eac56d01b2a14db65980 to your computer and use it in GitHub Desktop.
Много VS Один
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
import * as NotificationAction from 'actions/NotificationActions' | |
импортов может и не быть, если мы в обработчике нативно обрабатываем запросы | |
export default function 404({ status, statusText }, dispatch, getState) { | |
if (status === 404) { | |
dispatch(NotificationAction.send({message: statusText})) | |
} | |
} | |
Таких файлов будет ровно столько сколько будет обработчиков |
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
import XXX from 'Many-handler-xxx.js' | |
... | |
export { | |
XXX, | |
... столько же, сколько и импортов в файле | |
} | |
Этот файл нужен только для множественного импорта, при добавлении хэндлера нам нужно будет | |
работать с ним в обязательном порядке. То есть легко забыть сюда добавить обработчик |
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
import * as all from 'Many-index.js' | |
export default function checkHandlers(response, dispatch, getState) { | |
const isError = Object.keys(all) | |
.map(handler => all[handler](response, dispatch, getState)) | |
.some(status => status === false) | |
return !isError | |
} |
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
import * as NotificationAction from 'actions/NotificationActions' | |
тут может быть много импортов | |
const handlers = { | |
404({ status, statusText }, dispatch, getState) { | |
if (status === 404) { | |
dispatch(NotificationAction.send({message: statusText})) | |
} | |
}, | |
количество обработчиков n+ | |
} | |
export default function checkHandlers(response, dispatch, getState) { | |
const isError = Object.keys(handlers) | |
.map(handler => handlers[handler](response, dispatch, getState)) | |
.some(status => status === false) | |
return !isError | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment