Skip to content

Instantly share code, notes, and snippets.

@b2whats
Created December 1, 2015 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b2whats/eac56d01b2a14db65980 to your computer and use it in GitHub Desktop.
Save b2whats/eac56d01b2a14db65980 to your computer and use it in GitHub Desktop.
Много VS Один
import * as NotificationAction from 'actions/NotificationActions'
импортов может и не быть, если мы в обработчике нативно обрабатываем запросы
export default function 404({ status, statusText }, dispatch, getState) {
if (status === 404) {
dispatch(NotificationAction.send({message: statusText}))
}
}
Таких файлов будет ровно столько сколько будет обработчиков
import XXX from 'Many-handler-xxx.js'
...
export {
XXX,
... столько же, сколько и импортов в файле
}
Этот файл нужен только для множественного импорта, при добавлении хэндлера нам нужно будет
работать с ним в обязательном порядке. То есть легко забыть сюда добавить обработчик
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
}
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