Is it possible to put a function as a key in an ES6 computed key?
I'm reviewing this piece of code in the redux-connect library and I'm wondering if it is possible to put a function as a key in a computed key in ES6. How does it work and how is javascript interpreted?
export const reducer = handleActions({
[beginGlobalLoad]: state => ({
...state,
loaded: false,
}),
[endGlobalLoad]: state => ({
...state,
loaded: true,
})
....
}
with beginGlobalLoad is the function created by
export const beginGlobalLoad = createAction('@redux-conn/BEGIN_GLOBAL_LOAD');
I read the concept of dynamic computed key, but it doesn't say anything about using a function as a key for a property.
Thank you very much for your response
Library links: https://github.com/makeomatic/redux-connect/blob/master/modules/store.js
source to share
Not. Property keys must be either strings or characters. If you use a function, it will collapse like any other object, and this is usually not what you want.
However, the createAction
docs indicates that
createAction
also returns its type when used as a type inhandleAction
orhandleActions
.
which they achieve rewritingtoString
.
source to share