tommy351 / redux-example

A universal (isomorphic) web application example powered by Redux.
MIT License
33 stars 5 forks source link

Dispatch GET_USER multiple times #2

Open DevAlien opened 8 years ago

DevAlien commented 8 years ago

Hi, I've been playing around with your redux example and it is pretty cool, it does its job.

While checking the files, i run into the actions of the user and found that you dispatch the GET_USER 2 times, and the first time you don't do any actions. https://github.com/tommy351/redux-example/blob/master/src/actions/users.js Is there a reason for that?

Thanks for your time

tommy351 commented 8 years ago

The first dispatch means the request started, it can be used on loading indicator for example. The second dispatch will be either success or failed. Here's the content of actions:

// Dispatch #1: Started
{
  type: 'GET_USER'
}

// Dispatch #2: Success
{
  type: 'GET_USER',
  payload: {
    // ...
  }
}

// Dispatch #2: Failed
{
  type: 'GET_USER',
  payload: {
    // ...
  },
  error: true
}
DevAlien commented 8 years ago

Ah ok, so why not calling them with different names? For me it does not make a lot of sense to use the same action for 2 different things