Skip to content

Commit

Permalink
Move connect to the top
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 9, 2015
1 parent 8bb1277 commit b6eace8
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions modules/backends/HTML5.js
Expand Up @@ -129,6 +129,54 @@ export default class HTML5Backend {
this.clearCurrentDragSourceNode();
}

connect() {
return {
dragSource: this.connectSourceNode,
dragSourcePreview: this.connectSourcePreviewNode,
dropTarget: this.connectTargetNode
};
}

connectSourcePreviewNode(sourceId, node, options) {
this.sourcePreviewNodeOptions[sourceId] = options;
this.sourcePreviewNodes[sourceId] = node;

return () => {
delete this.sourcePreviewNodes[sourceId];
delete this.sourcePreviewNodeOptions[sourceId];
};
}

connectSourceNode(sourceId, node, options) {
const handleDragStart = (e) => this.handleDragStart(e, sourceId);

this.sourceNodeOptions[sourceId] = options;
node.setAttribute('draggable', true);
node.addEventListener('dragstart', handleDragStart);

return () => {
delete this.sourceNodeOptions[sourceId];
node.removeEventListener('dragstart', handleDragStart);
node.setAttribute('draggable', false);
};
}

connectTargetNode(targetId, node) {
const handleDragEnter = (e) => this.handleDragEnter(e, targetId);
const handleDragOver = (e) => this.handleDragOver(e, targetId);
const handleDrop = (e) => this.handleDrop(e, targetId);

node.addEventListener('dragenter', handleDragEnter);
node.addEventListener('dragover', handleDragOver);
node.addEventListener('drop', handleDrop);

return () => {
node.removeEventListener('dragenter', handleDragEnter);
node.removeEventListener('dragover', handleDragOver);
node.removeEventListener('drop', handleDrop);
};
}

getSpecifiedDropEffect() {
const sourceId = this.monitor.getSourceId();
const sourceNodeOptions = this.sourceNodeOptions[sourceId];
Expand Down Expand Up @@ -433,52 +481,4 @@ export default class HTML5Backend {
this.endDragIfSourceWasRemovedFromDOM();
}
}

connect() {
return {
dragSource: this.connectSourceNode,
dragSourcePreview: this.connectSourcePreviewNode,
dropTarget: this.connectTargetNode
};
}

connectSourcePreviewNode(sourceId, node, options) {
this.sourcePreviewNodeOptions[sourceId] = options;
this.sourcePreviewNodes[sourceId] = node;

return () => {
delete this.sourcePreviewNodes[sourceId];
delete this.sourcePreviewNodeOptions[sourceId];
};
}

connectSourceNode(sourceId, node, options) {
const handleDragStart = (e) => this.handleDragStart(e, sourceId);

this.sourceNodeOptions[sourceId] = options;
node.setAttribute('draggable', true);
node.addEventListener('dragstart', handleDragStart);

return () => {
delete this.sourceNodeOptions[sourceId];
node.removeEventListener('dragstart', handleDragStart);
node.setAttribute('draggable', false);
};
}

connectTargetNode(targetId, node) {
const handleDragEnter = (e) => this.handleDragEnter(e, targetId);
const handleDragOver = (e) => this.handleDragOver(e, targetId);
const handleDrop = (e) => this.handleDrop(e, targetId);

node.addEventListener('dragenter', handleDragEnter);
node.addEventListener('dragover', handleDragOver);
node.addEventListener('drop', handleDrop);

return () => {
node.removeEventListener('dragenter', handleDragEnter);
node.removeEventListener('dragover', handleDragOver);
node.removeEventListener('drop', handleDrop);
};
}
}

0 comments on commit b6eace8

Please sign in to comment.