reactjs - Is there a convention for Flux messages sent via the Dispatcher? -
i'm building first react front end , see number of conventions messages sent via dispatcher. e.g.
{ type: actiontypes.receive_raw_messages, rawmessages: rawmessages }
and
{ source: 'view_action', action: action }
what best message format use & why?
the short answer is, doesn't matter—as long stores right data. use following format:
{ type: 'action_type', // defined constant payload: { ... } // payload of json serializable types }
if app needs distinguish between actions initiated user , actions come server or other source, may considering adding source
key; use separate action types or data within payload purpose.
i make payload
object (never raw value) data can added without changing receiving sites. example, instead of
dispatch({type: action_type, payload: id})
i recommend
dispatch({type: action_type, payload: {id: id}})
of course, of may dictated flux implementation (if any) use. facebook dispatcher agnostic (you can send pretty want), implementations require specific keys (like type
, etc).
Comments
Post a Comment