(type, spec, collect, options = {})
| 9 | import isValidType from './utils/isValidType'; |
| 10 | |
| 11 | export default function DragSource(type, spec, collect, options = {}) { |
| 12 | checkDecoratorArguments('DragSource', 'type, spec, collect[, options]', ...arguments); // eslint-disable-line prefer-rest-params |
| 13 | let getType = type; |
| 14 | if (typeof type !== 'function') { |
| 15 | invariant( |
| 16 | isValidType(type), |
| 17 | 'Expected "type" provided as the first argument to DragSource to be ' + |
| 18 | 'a string, or a function that returns a string given the current props. ' + |
| 19 | 'Instead, received %s. ' + |
| 20 | 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', |
| 21 | type, |
| 22 | ); |
| 23 | getType = () => type; |
| 24 | } |
| 25 | invariant( |
| 26 | isPlainObject(spec), |
| 27 | 'Expected "spec" provided as the second argument to DragSource to be ' + |
| 28 | 'a plain object. Instead, received %s. ' + |
| 29 | 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', |
| 30 | spec, |
| 31 | ); |
| 32 | const createSource = createSourceFactory(spec); |
| 33 | invariant( |
| 34 | typeof collect === 'function', |
| 35 | 'Expected "collect" provided as the third argument to DragSource to be ' + |
| 36 | 'a function that returns a plain object of props to inject. ' + |
| 37 | 'Instead, received %s. ' + |
| 38 | 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', |
| 39 | collect, |
| 40 | ); |
| 41 | invariant( |
| 42 | isPlainObject(options), |
| 43 | 'Expected "options" provided as the fourth argument to DragSource to be ' + |
| 44 | 'a plain object when specified. ' + |
| 45 | 'Instead, received %s. ' + |
| 46 | 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', |
| 47 | collect, |
| 48 | ); |
| 49 | |
| 50 | return function decorateSource(DecoratedComponent) { |
| 51 | return decorateHandler({ |
| 52 | connectBackend: (backend, sourceId) => backend.connectDragSource(sourceId), |
| 53 | containerDisplayName: 'DragSource', |
| 54 | createHandler: createSource, |
| 55 | registerHandler: registerSource, |
| 56 | createMonitor: createSourceMonitor, |
| 57 | createConnector: createSourceConnector, |
| 58 | DecoratedComponent, |
| 59 | getType, |
| 60 | collect, |
| 61 | options, |
| 62 | }); |
| 63 | }; |
| 64 | } |
no test coverage detected