Skip to content

Commit f01e39b

Browse files
Refactoring
1 parent cc9bb82 commit f01e39b

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/vuedraggable.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ const draggableComponent = defineComponent({
143143
);
144144
this.headerOffset = headerOffset;
145145
this.footerOffset = footerOffset;
146-
const attributes = getComponentAttributes({ $attrs, componentData });
147146
this.defaultSlots = defaultSlots;
147+
const attributes = getComponentAttributes({ $attrs, componentData });
148148
const realRoot =
149149
isHtmlTag(tag) || isTransitionName(tag) ? tag : resolveComponent(tag);
150150
const mainNode = h(realRoot, attributes, children);
@@ -323,10 +323,8 @@ const draggableComponent = defineComponent({
323323
const list = component.realList;
324324
const context = { list, component };
325325
if (to !== related && list) {
326-
const destination = component.getUnderlyingVm(related);
327-
if (destination) {
328-
return Object.assign(destination, context);
329-
}
326+
const destination = component.getUnderlyingVm(related) || {};
327+
return { ...destination, ...context };
330328
}
331329
return context;
332330
},
@@ -337,10 +335,6 @@ const draggableComponent = defineComponent({
337335
return domIndex > numberIndexes - 1 ? numberIndexes : indexes[domIndex];
338336
},
339337

340-
getComponent() {
341-
return this.$slots.default()[0].componentInstance;
342-
},
343-
344338
onDragStart(evt) {
345339
this.context = this.getUnderlyingVm(evt.item);
346340
evt.item._underlying_vm_ = this.clone(this.context.element);
@@ -366,9 +360,9 @@ const draggableComponent = defineComponent({
366360
removeNode(evt.clone);
367361
return;
368362
}
369-
const oldIndex = this.context.index;
363+
const { index: oldIndex, element } = this.context;
370364
this.spliceList(oldIndex, 1);
371-
const removed = { element: this.context.element, oldIndex };
365+
const removed = { element, oldIndex };
372366
this.emitChanges({ removed });
373367
},
374368

@@ -411,12 +405,12 @@ const draggableComponent = defineComponent({
411405
...this.context,
412406
futureIndex
413407
};
414-
const sendEvt = {
408+
const sendEvent = {
415409
...evt,
416410
...{ relatedContext },
417411
...{ draggedContext }
418412
};
419-
return move(sendEvt, originalEvent);
413+
return move(sendEvent, originalEvent);
420414
},
421415

422416
onDragEnd() {

0 commit comments

Comments
 (0)