Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reducer doesn't work when root-state is Immutable #80

@florisvink

Description

@florisvink

Internally the module uses ImmutalbleJS for setting the api-states, but the api-reducer cannot be combined with existing reducers when the initialState of the store is Immutable:

For example:

const redux = require('redux');
const Immutable = require('immutable');
const redux_immutable = require('redux-immutable');
const redux_thunk = require('redux-thunk').default;
const redux_json_api = require('redux-json-api');

const api = redux_json_api.reducer;

const reducers = redux_immutable.combineReducers({api});
const initialState = Immutable.Map();
const middlewares = redux.applyMiddleware(redux_thunk);
const store = redux.createStore(reducers, initialState, middlewares );

store.subscribe(() => console.log(store.getState().toJS()) )

store.dispatch(redux_json_api.setEndpointHost('http://ip.jsontest.com/'));
store.dispatch(redux_json_api.setAccessToken('access_token_123123'));

store.dispatch(redux_json_api.readEndpoint('/'))

This code results in:
TypeError: Cannot read property 'endpoint' of undefined: getState().api.endpoint;

The code looks like:

const { host: apiHost, path: apiPath, headers } = getState().api.endpoint;

I think (in case the root-state is Immutable) this should be something like:

const { host: apiHost, path: apiPath, headers } = getState().get('api').endpoint;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions