我正在做一个采访反应代码演示,这是在reducer和selecters中使用ImmutableJS所必需的。但是,当我使用fromJS创建我的reducer并使用state.get(“ loading”,true)时,它给了我一个错误:TypeError: state.set is not a function.
。在他们给出的样本约简器中,它只使用state.set(),这很好,而且我发现在CombineReducer之后,样本约简器和我自己的约简器处于同一级别,这是什么问题?
这是用于使用ImmutableJS和CombineReducer构建redux reducer。
这是CombineReducer的用法。
import { createStore, applyMiddleware, combineReducers } from "redux";
const appReducer = combineReducers({
router: connectRouter(history),
...Object.keys(Core).reduce((accum, key) => {
accum[key] = Core[key].reducer;
console.log(accum);
return accum;
}, {})
});
我自己的减速器
const initialState = Immutable.fromJS({
fetchingRepos: false,
routes: [],
error: null
});
const reducer = {};
reducer[action.FETCH_REPOS] = (state, action) => {
// console.log(action);
return state.set("fetchingRepos", false);
};
降样器:
const reducer = {};
const initialState = Immutable.fromJS({
signedIn: false,
details: {}
});
reducer[actions.TOKEN_RECEIVED] = (state, event) => {
return state
.set("logIn", true)
.set("details", Immutable.fromJS(event.user));
};
我不知道使用state / set()的减样器是什么问题,但是我自己抛出了错误!
TypeError:state.set不是函数
27 |
28 | reducer[action.FETCH_REPOS] = function (state, action) {
29 | // console.log(action);
> 30 | return state.set("fetchingRepos", false);
31 | };
32 |