Skip to content

Commit 5ed0019

Browse files
Using event pull mode to determine if the element is cloning on remove
1 parent d0822e6 commit 5ed0019

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

src/vuedraggable.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ function delegateAndEmit(evtName) {
5454
};
5555
}
5656

57-
function groupIsClone(group) {
58-
if (!group) {
59-
return false;
60-
}
61-
const { pull } = group;
62-
if (typeof pull === "function") {
63-
return pull() === "clone";
64-
}
65-
return pull === "clone";
66-
}
67-
6857
const eventsListened = ["Start", "Add", "Remove", "Update", "End"];
6958
const eventsToEmit = ["Choose", "Sort", "Filter", "Clone"];
7059
const readonlyProperties = ["Move", ...eventsListened, ...eventsToEmit].map(
@@ -125,7 +114,6 @@ const draggableComponent = {
125114
transitionMode: false,
126115
noneFunctionalComponentMode: false,
127116
init: false,
128-
isCloning: false
129117
};
130118
},
131119

@@ -268,12 +256,6 @@ const draggableComponent = {
268256
return this.tag || this.element;
269257
},
270258

271-
getIsCloning() {
272-
const { group } = this.$attrs;
273-
const groupConsideringOption = group || this.getOptionGroup();
274-
return groupIsClone(groupConsideringOption);
275-
},
276-
277259
getOptionGroup() {
278260
const { options } = this;
279261
if (!options) {
@@ -404,7 +386,6 @@ const draggableComponent = {
404386

405387
onDragStart(evt) {
406388
this.context = this.getUnderlyingVm(evt.item);
407-
this.isCloning = this.getIsCloning();
408389
evt.item._underlying_vm_ = this.clone(this.context.element);
409390
draggingElement = evt.item;
410391
},
@@ -423,8 +404,8 @@ const draggableComponent = {
423404
},
424405

425406
onDragRemove(evt) {
426-
insertNodeAt(this.rootContainer, evt.item, evt.oldIndex);
427-
if (this.isCloning) {
407+
insertNodeAt(this.rootContainer, evt.item, evt.oldIndex);
408+
if ( evt.pullMode === "clone") {
428409
removeNode(evt.clone);
429410
return;
430411
}

tests/unit/vuedraggable.spec.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ describe("draggable.vue when initialized with list", () => {
371371
start(evt);
372372
});
373373

374-
it("sets the isCloning flag", () => {
375-
expect(vm.isCloning).toBe(false);
376-
})
377-
378374
it("sends a start event", async () => {
379375
await Vue.nextTick();
380376
expect(wrapper.emitted()).toEqual({
@@ -602,9 +598,6 @@ describe("draggable.vue when initialized with list", () => {
602598
propsData: {
603599
list: items
604600
},
605-
attrs: {
606-
group: { pull: "clone" }
607-
},
608601
slots: {
609602
default: items.map(item => `<div>${item}</div>`),
610603
}
@@ -617,10 +610,6 @@ describe("draggable.vue when initialized with list", () => {
617610
start(evt);
618611
});
619612

620-
it("sets the isCloning flag", () => {
621-
expect(vm.isCloning).toBe(true);
622-
})
623-
624613
describe("when remove is called", () => {
625614
beforeEach(() => {
626615
var clone = item.cloneNode(true);
@@ -630,6 +619,7 @@ describe("draggable.vue when initialized with list", () => {
630619
remove({
631620
item,
632621
clone,
622+
pullMode: "clone",
633623
oldIndex: 1
634624
});
635625
})
@@ -649,6 +639,7 @@ describe("draggable.vue when initialized with list", () => {
649639
expect(wrapper.emitted().remove).toEqual([[{
650640
item,
651641
clone: item,
642+
pullMode: "clone",
652643
oldIndex: 1
653644
}]]);
654645
})
@@ -684,10 +675,6 @@ describe("draggable.vue when initialized with list", () => {
684675
start(evt);
685676
});
686677

687-
it("sets the isCloning flag", () => {
688-
expect(vm.isCloning).toBe(true);
689-
})
690-
691678
describe("when remove is called", () => {
692679
beforeEach(() => {
693680
var clone = item.cloneNode(true);
@@ -697,6 +684,7 @@ describe("draggable.vue when initialized with list", () => {
697684
remove({
698685
item,
699686
clone,
687+
pullMode: "clone",
700688
oldIndex: 1
701689
});
702690
})
@@ -716,6 +704,7 @@ describe("draggable.vue when initialized with list", () => {
716704
expect(wrapper.emitted().remove).toEqual([[{
717705
item,
718706
clone: item,
707+
pullMode: "clone",
719708
oldIndex: 1
720709
}]]);
721710
})

0 commit comments

Comments
 (0)