Code Monkey home page Code Monkey logo

Comments (7)

lukaskostial avatar lukaskostial commented on July 25, 2024 1

I'm sorry I didn't make myself clear. What I meant is below:

import { createStore } from 'redux'
import { combineReducers } from 'redux-immutable'
import { Map } from 'immutable'

const reducerA = (state = "A", action) => state
const reducerB = (state = "B", action) => state

const createReducer = (additionalReducers) => {
    return combineReducers({
      ...additionalReducers,
      a: reducerA,
      b: reducerB
    })
}
// Create store with empty initial state
const store = createStore(createReducer(), Map({}))
console.log(store.getState().toJS())

// Then dynamically load another module with reducerC (e.g. via SystemJS System.import)

const reducerC = (state = "C", action) => state
const reducerD = (state = "D", action) => state

const newModuleReducer = combineReducers({
  c: reducerC,
  d: reducerD
})

// Add the loaded reducer to the store. The store structure should be:
// {
//  a: "A",
//  b: "B",
//  inner: { c: "C", d: "D" }
// }
store.replaceReducer(createReducer({inner: newModuleReducer}))

console.log(store.getState().toJS())

This works OK with standard redux.

from redux-immutable.

gajus avatar gajus commented on July 25, 2024

What is the problem with explicitly passing Immutable.Map() as the initial value?

from redux-immutable.

namjul avatar namjul commented on July 25, 2024

thats fine, just pointing out that without it, it throws an error and because of
reduxjs/redux#1189 (comment)
that maybe it should be possible to not specific an initialstate

from redux-immutable.

lukaskostial avatar lukaskostial commented on July 25, 2024

Shouldn't there be an option to let reducers (even those dynamically loaded) to define their initial state via default parameter ?

from redux-immutable.

gajus avatar gajus commented on July 25, 2024

Shouldn't there be an option to let reducers (even those dynamically loaded) to define their initial state via default parameter ?

Are you saying something different from what was already said?

from redux-immutable.

lukaskostial avatar lukaskostial commented on July 25, 2024

What is the problem with explicitly passing Immutable.Map() as the initial value?

The problem is when you dynamically load a module and want to updateReducers but don't what to update initialState (not sure if it's even possible but I'm not that familiar with redux yet). Plus your dynamically-loaded reducer is also produced by redux-immutable combineReducers.

from redux-immutable.

gajus avatar gajus commented on July 25, 2024

I am just not following you, at all. For me to further assist with this issue, I'd need a code example.

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.