Redux - do I need to keep action types separately? -
i'm defining action types in separate file:
export const set_some_id = 'set_some_id'; export const set_some_name = 'set_some_name'; ...
then in action creators file doing this:
import * atypes './actiontypes.js'; export function setsomeid(id) { return { type: atypes.set_some_id} } export function setsomename(name) { return { type: atypes.set_some_name} } ...
i feel should dispense having action types in separate file , in actioncreators.js file:
export function setsomeid(id) { return { type: 'set_some_id'} }
is necessary, i.e. application grows become apparent right thing do?
you can return string without defining types in separate file. however, bad coding practice in general - arbitrary strings, ones used across multiple files, should defined constant variable , imported wherever used.
in case, have use action type strings within action creators , within 1 or more of reducers (multiple reducers can set respond single action type). defining action types constants , import them wherever used reduces risk of accidentally misspelling them in 1 of sources in they're used, can cause lot of wasted time debugging simple bug / misspelling.
also, advantageous define of action types constants.. allows , other team members see action types possibly several action creators.
the redux api docs more or less it's you, goes list of positives defining action types constants: http://redux.js.org/docs/recipes/reducingboilerplate.html#actions (right before action creators section)
Comments
Post a Comment