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

Commits on May 6, 2016

  1. Compose Reducers with a common action

    ```
    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
    dustinmoorenet committed May 6, 2016
    Configuration menu
    Copy the full SHA
    403aa45 View commit details
    Browse the repository at this point in the history