I have some "dumb" question, sorry, but I really don't understand how it works.
In this createReducer call we are passing the second argument - js object (as I understand).
But I didn't see any key... only function. How it can works?
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
}
}
}
I expected to see some like:
{
[ActionTypes.ADD_TODO] : (state, action) => {
let text = action.text.trim()
return [ ...state, text ]
}
}
The same with this construction: it's a function where is the key? How it can be?
const dynamicRoutes = {
component : AppComponent,
childRoutes : [
{
path : "/",
getComponent(location, cb) {
System.import("../modules/landing-page/LandingPage.module")
.then(loadRoute(cb))
.catch(errorLoading);
}
}
]
};
Thanks for any help!