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

Allow nested reducers in handleActions #215

Closed
roboslone opened this issue May 29, 2017 · 4 comments
Closed

Allow nested reducers in handleActions #215

roboslone opened this issue May 29, 2017 · 4 comments

Comments

@roboslone
Copy link

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?

@roboslone
Copy link
Author

ping

@yangmillstheory
Copy link
Contributor

That sounds reasonable; feel free to take a shot at a pull request. I would ask that you preserve backwards-compatibility as well. I believe the key algorithm is already in this library. What do you think of taking up this work yourself?

@roboslone
Copy link
Author

Not sure if I'm up to the task, I have little experience with JS =/

@roboslone
Copy link
Author

@zcei @yangmillstheory Thanks!

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

No branches or pull requests

2 participants