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

Function DragLayer

packages/react-dnd/src/DragLayer.js:10–126  ·  view source on GitHub ↗
(collect, options = {})

Source from the content-addressed store, hash-verified

8import checkDecoratorArguments from './utils/checkDecoratorArguments';
9
10export default function DragLayer(collect, options = {}) {
11 checkDecoratorArguments('DragLayer', 'collect[, options]', ...arguments); // eslint-disable-line prefer-rest-params
12 invariant(
13 typeof collect === 'function',
14 'Expected "collect" provided as the first argument to DragLayer ' +
15 'to be a function that collects props to inject into the component. ',
16 'Instead, received %s. ' +
17 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-layer.html',
18 collect,
19 );
20 invariant(
21 isPlainObject(options),
22 'Expected "options" provided as the second argument to DragLayer to be ' +
23 'a plain object when specified. ' +
24 'Instead, received %s. ' +
25 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-layer.html',
26 options,
27 );
28
29 return function decorateLayer(DecoratedComponent) {
30 const { arePropsEqual = shallowEqualScalar } = options;
31 const displayName =
32 DecoratedComponent.displayName ||
33 DecoratedComponent.name ||
34 'Component';
35
36 class DragLayerContainer extends Component {
37 static DecoratedComponent = DecoratedComponent;
38
39 static displayName = `DragLayer(${displayName})`;
40
41 static contextTypes = {
42 dragDropManager: PropTypes.object.isRequired,
43 }
44
45 getDecoratedComponentInstance() {
46 invariant(
47 this.child,
48 'In order to access an instance of the decorated component it can ' +
49 'not be a stateless component.',
50 );
51 return this.child;
52 }
53
54 shouldComponentUpdate(nextProps, nextState) {
55 return !arePropsEqual(nextProps, this.props) ||
56 !shallowEqual(nextState, this.state);
57 }
58
59 constructor(props, context) {
60 super(props);
61 this.handleChange = this.handleChange.bind(this);
62
63 this.manager = context.dragDropManager;
64 invariant(
65 typeof this.manager === 'object',
66 'Could not find the drag and drop manager in the context of %s. ' +
67 'Make sure to wrap the top-level component of your app with DragDropContext. ' +

Callers 1

CustomDragLayer.jsFile · 0.90

Calls 1

checkDecoratorArgumentsFunction · 0.85

Tested by

no test coverage detected