Code Monkey home page Code Monkey logo

Comments (5)

pukapukan avatar pukapukan commented on June 27, 2024

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

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

from redux-immutable.

 avatar commented on June 27, 2024

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.

from redux-immutable.

gajus avatar gajus commented on June 27, 2024

No. You are talking about redux-immutable v1.

On Mar 8, 2016, at 08:32, Daniel Aviv [email protected] 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.

from redux-immutable.

 avatar commented on June 27, 2024

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..)?

from redux-immutable.

gajus avatar gajus commented on June 27, 2024

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

from redux-immutable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.