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 } 

https://github.com/facebook/flux/blob/master/examples/flux-chat/js/actions/chatserveractioncreators.js#l21

and

{   source: 'view_action',   action: action } 

http://facebook.github.io/react/blog/2014/09/24/testing-flux-applications.html#putting-it-all-together

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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -