【发布时间】:2017-01-19 10:54:28
【问题描述】:
我有一些“愚蠢”的问题,抱歉,但我真的不明白它是如何工作的。
在这个 createReducer 调用中,我们传递了第二个参数 - js 对象(据我所知)。
但我没有看到任何键……只有功能。它是如何工作的?
export const todos = createReducer([], {
[ActionTypes.ADD_TODO](state, action) {
let text = action.text.trim()
return [ ...state, text ]
}
})
function createReducer(initialState, handlers) {
return function reducer(state = initialState, action) {
if (handlers.hasOwnProperty(action.type)) {
return handlers[action.type](state, action)
} else {
return state
}
}
}
我预计会看到类似的内容:
{
[ActionTypes.ADD_TODO] : (state, action) => {
let text = action.text.trim()
return [ ...state, text ]
}
}
这个结构也一样:它是一个函数,关键在哪里?怎么可能?
const dynamicRoutes = {
component : AppComponent,
childRoutes : [
{
path : "/",
getComponent(location, cb) {
System.import("../modules/landing-page/LandingPage.module")
.then(loadRoute(cb))
.catch(errorLoading);
}
}
]
};
感谢您的帮助!
【问题讨论】:
-
谢谢你们现在我明白了。