Giter Club home page Giter Club logo

Comments (9)

fgarcia avatar fgarcia commented on August 27, 2024

The problem is that most code expects state.router to exist, however the new combineReducers you are using causes state to be a Map() which breaks access to state.router

You might just go back to the standard combine function or wrap the main reducer to inject the "router" attribute into the returned state

from redux-immutablejs.

clinyong avatar clinyong commented on August 27, 2024

Thanks @fgarcia. But if I use the standard combine function, how to make state immutable. Could you give me some code?

from redux-immutablejs.

fgarcia avatar fgarcia commented on August 27, 2024

I've just upgraded back to full Immutable state, so keep using the immutable combine and do this:

// DEFAULT const routerStateSelector = state => state.router;
const routerStateSelector = state => state.get('router');
//  ...
reduxReactRouter({ routes, createHistory, routerStateSelector })

all credit goes to acdlite/redux-router#67 (comment)

from redux-immutablejs.

clinyong avatar clinyong commented on August 27, 2024

@fgarcia , I try your solution, like below

import { createStore, compose, applyMiddleware } from 'redux'
import { reduxReactRouter } from 'redux-router'
import createHistory from 'history/lib/createBrowserHistory'
import routes from './routes'
import { rootReducer } from './reducers'                                                                                                                                    import thunk from 'redux-thunk'
import Immutable from 'immutable'

const state = Immutable.fromJS({})
const initialState = rootReducer(state)
const routerStateSelector = state => state.get('router')

const finalCreateStore = compose(
  applyMiddleware(thunk),
  reduxReactRouter({
    routerStateSelector,
    routes,
    createHistory
  })
)(createStore)

export default function configureStore () {
  return finalCreateStore(rootReducer, initialState)
}

But it still not works...I debug in the routerStateReducer.js file

function routerStateReducer(state, action) {
  if (state === undefined) state = null;

  var _extends2;

  console.log(action);  // add this

  switch (action.type) {
    case _constants.ROUTER_DID_CHANGE:
      return action.payload;
    case _constants.REPLACE_ROUTES:
      if (!state) return state;
      return _extends({}, state, (_extends2 = {}, _extends2[_constants.DOES_NEED_REFRESH] = true, _extends2));
    default:
      return state;
  }
}

...

And the console prints

Object {type: "INIT"}
Object {type: "8.8.l.3.j.0.m.g.q.f.r"}
undefined

from redux-immutablejs.

neverfox avatar neverfox commented on August 27, 2024

@fgarcia @clinyong It should be state => state.get('router').toJS(). redux-router needs a POJO.

from redux-immutablejs.

fgarcia avatar fgarcia commented on August 27, 2024

@neverfox only state is an ImmutableJS object, in my code the result of get already returns a POJO and I am already using this package combine function. Maybe is it different for the OP?

from redux-immutablejs.

neverfox avatar neverfox commented on August 27, 2024

Ah, I see. I had assumed that redux-immutablejs did a fromJS recursively. I don't use this library personally because I don't really see the advantage of making the top level state layer immutable (mainly because it breaks plugins like redux-router and redux-forms, without adding much benefit that I can see). I prefer to just apply ImmutableJS to the values of my top level state keys (in my custom reducers' initialState).

from redux-immutablejs.

clinyong avatar clinyong commented on August 27, 2024

@neverfox state => state.get('router').toJS() is not the right way... The action still be undefined.

This library seems too complicated for me, and I decide to use ImmutableJS just in reducers as @neverfox said.

Thanks guys.

from redux-immutablejs.

neverfox avatar neverfox commented on August 27, 2024

@clinyong I just took at stab at it by looking at the source code. @fgarcia is right that, at the very least, it doesn't need toJS() but since it wasn't working for you even without that, I'm at a loss and don't really have much of a reason to pursue it any deeper. Good luck!

from redux-immutablejs.

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.