react-dnd
Version:
Drag and Drop for React
46 lines • 1.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var wrapConnectorHooks_1 = __importDefault(require("./wrapConnectorHooks"));
var shallowequal_1 = __importDefault(require("shallowequal"));
function createTargetConnector(backend) {
var currentHandlerId;
var currentDropTargetNode;
var currentDropTargetOptions;
var disconnectCurrentDropTarget;
function reconnectDropTarget() {
if (disconnectCurrentDropTarget) {
disconnectCurrentDropTarget();
disconnectCurrentDropTarget = undefined;
}
if (currentHandlerId && currentDropTargetNode) {
disconnectCurrentDropTarget = backend.connectDropTarget(currentHandlerId, currentDropTargetNode, currentDropTargetOptions);
}
}
function receiveHandlerId(handlerId) {
if (handlerId === currentHandlerId) {
return;
}
currentHandlerId = handlerId;
reconnectDropTarget();
}
var hooks = wrapConnectorHooks_1.default({
dropTarget: function connectDropTarget(node, options) {
if (node === currentDropTargetNode &&
shallowequal_1.default(options, currentDropTargetOptions)) {
return;
}
currentDropTargetNode = node;
currentDropTargetOptions = options;
reconnectDropTarget();
},
});
return {
receiveHandlerId: receiveHandlerId,
hooks: hooks,
};
}
exports.default = createTargetConnector;
//# sourceMappingURL=createTargetConnector.js.map