Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose Reducers with a common action #1698

Closed

Conversation

dustinmoorenet
Copy link

@dustinmoorenet dustinmoorenet commented May 6, 2016

function firstName(state = '', action = {}) {
  if (action.type === SET_FIRST_NAME) {
    return action.payload
  }

  return state
}

function lastName(state = '', action = {}) {
  if (action.type === SET_LAST_NAME) {
    return action.payload
  }

  return state
}

const reducer = combineReducers({
  firstName,
  lastName
})

function handleSetFullName(state, action) {
  if (action.type === SET_FULL_NAME) {
    const parts = action.payload.split(' ')

    return {
      ...state,
      firstName: parts[0],
      lastName: parts[1]
    }
  }

  return state
}

export default composeReducers(
  reducer,
  handleSetFullName
);

#897

```
function firstName(state = '', action = {}) {
  if (action.type === SET_FIRST_NAME) {
    return action.payload
  }

  return state
}

function lastName(state = '', action = {}) {
  if (action.type === SET_LAST_NAME) {
    return action.payload
  }

  return state
}

const reducer = combineReducers({
  firstName,
  lastName
})

function handleSetFullName(state, action) {
  if (action.type === SET_FULL_NAME) {
    const parts = action.payload.split(' ')

    return {
      ...state,
      firstName: parts[0],
      lastName: parts[1]
    }
  }

  return state
}

export default composeReducers(
  reducer,
  handleSetFullName
);
```

reduxjs#897
@gaearon
Copy link
Contributor

gaearon commented May 6, 2016

This is not very commonly requested so we will probably not include this in core public API.

Something like this is available in https://github.com/acdlite/reduce-reducers.

@gaearon
Copy link
Contributor

gaearon commented May 6, 2016

I appreciate the effort though!

@gaearon gaearon closed this May 6, 2016
@dustinmoorenet
Copy link
Author

No problem, thanks for taking time to create redux and for looking at my pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants