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

Function createSourceFactory

packages/react-dnd/src/createSourceFactory.js:7–97  ·  view source on GitHub ↗
(spec)

Source from the content-addressed store, hash-verified

5const REQUIRED_SPEC_METHODS = ['beginDrag'];
6
7export default function createSourceFactory(spec) {
8 Object.keys(spec).forEach((key) => {
9 invariant(
10 ALLOWED_SPEC_METHODS.indexOf(key) > -1,
11 'Expected the drag source specification to only have ' +
12 'some of the following keys: %s. ' +
13 'Instead received a specification with an unexpected "%s" key. ' +
14 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html',
15 ALLOWED_SPEC_METHODS.join(', '),
16 key,
17 );
18 invariant(
19 typeof spec[key] === 'function',
20 'Expected %s in the drag source specification to be a function. ' +
21 'Instead received a specification with %s: %s. ' +
22 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html',
23 key,
24 key,
25 spec[key],
26 );
27 });
28 REQUIRED_SPEC_METHODS.forEach((key) => {
29 invariant(
30 typeof spec[key] === 'function',
31 'Expected %s in the drag source specification to be a function. ' +
32 'Instead received a specification with %s: %s. ' +
33 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html',
34 key,
35 key,
36 spec[key],
37 );
38 });
39
40 class Source {
41 constructor(monitor) {
42 this.monitor = monitor;
43 this.props = null;
44 this.component = null;
45 }
46
47 receiveProps(props) {
48 this.props = props;
49 }
50
51 receiveComponent(component) {
52 this.component = component;
53 }
54
55 canDrag() {
56 if (!spec.canDrag) {
57 return true;
58 }
59
60 return spec.canDrag(this.props, this.monitor);
61 }
62
63 isDragging(globalMonitor, sourceId) {
64 if (!spec.isDragging) {

Callers 1

DragSourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected