Earlier quoted context omitted.
Is it acceptable to dispatch inside your action creators? I'm somewhat new to redux but I got the impression that dispatch should be used inside mapDispatchToProps.
It's an example of the thunk pattern. Thunks are used when you have an async call, e.g. getFoos. Then your action creator would be function requestFoos() { return { type: REQ_FOOS } } function gotFoos(foos) { return { type: GOT_FOOS, foos } } export function getFoos() { return function(dispatch) { dispatch(requestFoos()); myFooProvider .getFoos() .then(function(foos) { dispatch(gotFoos(foos)); }); } } Really useful f…
Show HN: Build your first real world React.js application
41–46 of 46 posts
Re: Show HN: Build your first real world React.js application
#42Earlier quoted context omitted.
Is it acceptable to dispatch inside your action creators? I'm somewhat new to redux but I got the impression that dispatch should be used inside mapDispatchToProps.
I found that redux only made sense once I started using redux-thunk to dispatch and handle quite a bit of logic inside the action-creators.
Re: Show HN: Build your first real world React.js application
#43Earlier quoted context omitted.
It is possible to use Symbols instead of strings, which yields some nice improvements in terms of no longer allowing construction of actions with potentially misspelled strings, etc.
That's not actually a good idea: https://github.com/acdlite/redux-actions/issues/20#issuecomm...
Regardless of serialization/replay-ability, the core of the suggestion is to `import` some constant instead of using raw strings. Symbols have the benefit of forcing an import, whereas a list of constants that reference strings can be "bypassed" by writing the correct string in a random file. In fact, the redux actions documentation uses the following example of this pattern as the first example.
``` // fileA const ADD_TODO = 'ADD_TODO'
//fileB { type: ADD_TODO, text: 'Build my first Redux app' } ```
Re: Show HN: Build your first real world React.js application
#44I find I am more productive with vue.js. It is much less intrusive on my coding style. I believe react.js is mainly popular because of FB's support. Much in the same way Angular became so widely used due to Google backing. I too have fallen for the myth that Open-Source projects backed by huge companies are always better. Do your homework. Don't believe the hype.
Would you mind sharing your rationale? As someone approaching web front end development from a clean slate (es6 isn't the monster I though javascript to be, though there are some warts), can you tell me what vue does better than the alternatives (e.g., react)? I'm building my first prototype of a web-based application right now, and sticking with raw ES6 to keep the cognitive load down (relative to javascript + a fra…
Re: Show HN: Build your first real world React.js application
#45Earlier quoted context omitted.
That's not actually a good idea: https://github.com/acdlite/redux-actions/issues/20#issuecomm...
You link to a comment which indicates serialization is a potentially breaking issue. This is a tradeoff that does not affect the routine behavior of redux but may affect advanced use cases such as allowing user upload of action history for bug reports. Regardless of serialization/replay-ability, the core of the suggestion is to `import` some constant instead of using raw strings. Symbols have the benefit of forcing a…
Re: Show HN: Build your first real world React.js application
#46I just went through the first tutorial and it's well written. However, I just had to try it with AngularJs and jQuery as well. Here are the results http://goo.gl/V0NvkC In such a simple example, I think jquery wins. However, more complicated solutions might be better suited towards frameworks like Angular and React.
The jQuery app may seem "the simplest", but it has no notion of components - https://jsbin.com/jupagugofe/edit?html,js,output , whereas the angular( https://jsbin.com/mepijibika/edit?html,js,output ) and react( http://jsbin.com/gijigiqecu/edit?js,output ) apps do.