我有一个名为 DraggableAsset 的组件,它由 DragSource 装饰:
@DragSource('DRAGGABLE_ASSET', spec, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging(),
}))
export default class DraggableAsset extends Component {
static propTypes = {
asset: PropTypes.instanceOf(AssetModel).isRequired,
connectDragSource: PropTypes.func.isRequired,
isDragging: PropTypes.bool.isRequired,
};
render() {
const {isDragging, connectDragSource, asset} = this.props;
return connectDragSource(
<div style={{opacity: isDragging ? 0.5 : 1}}>
<img width={200} src={asset.get('url')} />
<p>{asset.get('name')}</p>
</div>,
);
}
}
我想参数化'DRAGGABLE_ASSET'
字符串。我可以用下面的另一个装饰器来实现吗?
export function DraggableAssetDecorator(target, name, descriptor) {
Object.defineProperty(target, 'TYPE', {value: 'DRAGGABLE_VIDEO'});
return target;
}