Skip to content

Allow nested reducers in handleActions #215

@roboslone

Description

@roboslone

It was really surprising for me that createActions can handle nested objects while handleActions can't. I think this example looks very natural and readable:

const defaultState = {
    query: undefined
}

export const actionCreators = createActions({
    SEARCH: {
        SET_QUERY: text => text,
    }
})

export const reducer = handleActions({
    SEARCH: {
        SET_QUERY: (state = defaultState, action = {}) => {
            return {...state, query: action.payload}
        },
    },
}, defaultState)

But it doesn't work. Instead reducer must be:

export const reducer = handleActions({
    'SEARCH/SET_QUERY': (state = defaultState, action = {}) => {
        console.log('reducer.search.setQuery <-', state, ',', action)
        return {...state, query: action.payload}
    },
}, defaultState)

My IDE autocompletes with first example and doesn't with the second.

Would it be possible to allow such nested structures in handleActions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions