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

Uncaught TypeError: reducer is not a function #25

Closed
ghost opened this issue Mar 3, 2016 · 5 comments
Closed

Uncaught TypeError: reducer is not a function #25

ghost opened this issue Mar 3, 2016 · 5 comments
Labels

Comments

@ghost
Copy link

ghost commented Mar 3, 2016

Hey guys,
Thanks for an awesome repo,
I updated to the latest version and ran into this error,

Uncaught TypeError: reducer is not a function at combineReducers.js:51 ( using Webpack )

My code:

var state = Immutable.Map({});

var itemsReducer = {

    items: {

        CONSTRUCT () {
            return Immutable.Map([
                {
                    id: 1,
                    name: 'foo',
                    done: true
                },
                {
                    id: 2,
                    name: 'bar',
                    done: false
                },
                {
                    id: 3,
                    name: 'baz',
                    done: false
                }
            ])
        },

        ADD_ITEM (domain, action) {
            return domain
                .push(Immutable.Map({
                    id: 1,
                    name: 'test',
                    done: false
                }));
        }
    }
};

var reducer = combineReducers({
    items: itemsReducer
});

Only happens with the latest version,
Am I missing something?

@pukapukan
Copy link

A reducer needs to be a function - but you're passing in an object.

http://redux.js.org/docs/basics/Reducers.html

@ghost
Copy link
Author

ghost commented Mar 8, 2016

Hey @pukapukan, Thanks for the answer, but still something is not quite clear to me..
redux-immutable supposed to work with canonical reducer composition right?
in the example given in redux docs there is no use of it,

in the CNC examples: https://github.com/gajus/canonical-reducer-composition
they also passing an object to redux-immutable's combineReducers helper:

reducer = {
    countries: {
        ADD_COUNTRY: (domain, action) {
            return domain.push(action.country);
        },
        REMOVE_COUNTRY: (domain, action) {
            return domain.delete(domain.indexOf(action.country));
        }
    },
    cities: {
        // Using a constructor.
        CONSTRUCT () {
            return [
                'Rome',
                'Tokyo',
                'Berlin'
            ];
        },
        ADD_CITY (domain, action) {
            return domain.push(action.city);
        },
        REMOVE_CITY (domain, action) {
            return domain.delete(domain.indexOf(action.city));
        }
    },
    // Implement a sub-domain reducer map.
    user: {
        names: {
            ADD_NAME (domain, action) {
                return domain.push(action.name);
            },
            REMOVE_NAME (domain, action) {
                return domain.delete(domain.indexOf(action.name));
            }
        }
    }
};

reducer = combineReducers(reducer);

I'm a little confused.

@gajus
Copy link
Owner

gajus commented Mar 8, 2016

No. You are talking about redux-immutable v1.

On Mar 8, 2016, at 08:32, Daniel Aviv notifications@github.com wrote:

Hey @pukapukan, Thanks for the answer, but still something is not quite clear to me..
redux-immutable supposed to work with canonical reducer composition right?
in the example given in redux docs there is no use of it,

in the CNC examples:
they also passing an object to redux-immutable's combineReducers helper:

`reducer = {
countries: {
ADD_COUNTRY: (domain, action) {
return domain.push(action.country);
},
REMOVE_COUNTRY: (domain, action) {
return domain.delete(domain.indexOf(action.country));
}
},
cities: {
// Using a constructor.
CONSTRUCT () {
return [
'Rome',
'Tokyo',
'Berlin'
];
},
ADD_CITY (domain, action) {
return domain.push(action.city);
},
REMOVE_CITY (domain, action) {
return domain.delete(domain.indexOf(action.city));
}
},
// Implement a sub-domain reducer map.
user: {
names: {
ADD_NAME (domain, action) {
return domain.push(action.name);
},
REMOVE_NAME (domain, action) {
return domain.delete(domain.indexOf(action.name));
}
}
}
};

reducer = combineReducers(reducer);`

I'm a little confused.


Reply to this email directly or view it on GitHub.

@ghost
Copy link
Author

ghost commented Mar 8, 2016

Got it @gajus,
Thanks for the quick response,
When i use a regular reducer function, I get the state argument as a plain JavaScript object rather than Immutable.js instance.
Is this the default behavior? if so.. what are the benefits of using redux-immutable? and how to use it properly?
What are the best practices of writing complex reducers and use immutable.js instance as a state?
Do you have any up to date implementation examples? (Including complex reducers with domains and nested domains, actions, etc..)?

@gajus
Copy link
Owner

gajus commented Mar 8, 2016

@DanielAviv1 you will need to open a separate question (assuming one does not exist) for each of those questions.

@gajus gajus closed this as completed Mar 8, 2016
@gajus gajus added the invalid label Mar 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants