MCPcopy Create free account
hub / github.com/react-dnd/react-dnd / DropTarget

Function DropTarget

packages/react-dnd/src/DropTarget.js:11–64  ·  view source on GitHub ↗
(type, spec, collect, options = {})

Source from the content-addressed store, hash-verified

9import isValidType from './utils/isValidType';
10
11export default function DropTarget(type, spec, collect, options = {}) {
12 checkDecoratorArguments('DropTarget', '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, true),
17 'Expected "type" provided as the first argument to DropTarget to be ' +
18 'a string, an array of strings, or a function that returns either given ' +
19 'the current props. Instead, received %s. ' +
20 'Read more: http://react-dnd.github.io/react-dnd/docs-drop-target.html',
21 type,
22 );
23 getType = () => type;
24 }
25 invariant(
26 isPlainObject(spec),
27 'Expected "spec" provided as the second argument to DropTarget to be ' +
28 'a plain object. Instead, received %s. ' +
29 'Read more: http://react-dnd.github.io/react-dnd/docs-drop-target.html',
30 spec,
31 );
32 const createTarget = createTargetFactory(spec);
33 invariant(
34 typeof collect === 'function',
35 'Expected "collect" provided as the third argument to DropTarget 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-drop-target.html',
39 collect,
40 );
41 invariant(
42 isPlainObject(options),
43 'Expected "options" provided as the fourth argument to DropTarget to be ' +
44 'a plain object when specified. ' +
45 'Instead, received %s. ' +
46 'Read more: http://react-dnd.github.io/react-dnd/docs-drop-target.html',
47 collect,
48 );
49
50 return function decorateTarget(DecoratedComponent) {
51 return decorateHandler({
52 connectBackend: (backend, targetId) => backend.connectDropTarget(targetId),
53 containerDisplayName: 'DropTarget',
54 createHandler: createTarget,
55 registerHandler: registerTarget,
56 createMonitor: createTargetMonitor,
57 createConnector: createTargetConnector,
58 DecoratedComponent,
59 getType,
60 collect,
61 options,
62 });
63 };
64}

Callers 15

Dustbin.jsFile · 0.90
Dustbin.jsFile · 0.90
Dustbin.jsFile · 0.90
Dustbin.jsFile · 0.90
Card.jsFile · 0.90
Container.jsFile · 0.90
Card.jsFile · 0.90
Card.jsFile · 0.90
TargetBox.jsFile · 0.90
BoardSquare.jsFile · 0.90
TargetBoxClass · 0.90
Dustbin.jsFile · 0.90

Calls 5

checkDecoratorArgumentsFunction · 0.85
isValidTypeFunction · 0.85
createTargetFactoryFunction · 0.85
decorateHandlerFunction · 0.85
connectDropTargetMethod · 0.45

Tested by

no test coverage detected