如何在const { Types, Creators }
中分配以下代码,我的意思是类型将会持有什么以及创作者将会持有什么。
const { Types, Creators } = createActions({
userRequest: ['username'],
userSuccess: ['avatar'],
userFailure: null
})
var createActions = (function (config, options) {
if (R.isNil(config)) {
throw new Error('an object is required to setup types and creators');
}
if (R.isEmpty(config)) {
throw new Error('empty objects are not supported');
}
return {
Types: convertToTypes(config, options),
Creators: convertToCreators(config, options)
};
})
答案 0 :(得分:3)
语法是对象解构赋值。 Types
和Creators
将被定义为从Types
调用返回的对象返回的Creators
和createActions()
属性。例如
const {Types, Creators} = (() => {
return {Types:0, Creators:1}
})();
console.log(Types, Creators)
答案 1 :(得分:1)
这称为destructuring assignment,它查看返回的对象并为变量分配正确的键。可以把它想象成:
Observable.next()