Skip to content

Commit 80304f2

Browse files
refactoring update list
1 parent 949ffa0 commit 80304f2

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

dist/vuedraggable.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4+
35
(function () {
46
"use strict";
57

@@ -22,11 +24,11 @@
2224
}).indexOf(element);
2325
}
2426

25-
function updatePosition(collection, oldIndex, newIndex) {
26-
if (collection) {
27-
collection.splice(newIndex, 0, collection.splice(oldIndex, 1)[0]);
28-
}
29-
}
27+
// function updatePosition (collection, oldIndex, newIndex) {
28+
// if (collection) {
29+
// collection.splice(newIndex, 0, collection.splice(oldIndex, 1)[0])
30+
// }
31+
// }
3032

3133
function _computeIndexes(slots, children) {
3234
return !slots ? [] : Array.prototype.map.call(children, function (elt) {
@@ -149,6 +151,11 @@
149151
_this3.visibleIndexes = _computeIndexes(_this3.getChildrenNodes(), _this3.rootContainer.children);
150152
});
151153
},
154+
updatePosition: function updatePosition(oldIndex, newIndex) {
155+
if (this.list) {
156+
this.list.splice(newIndex, 0, this.list.splice(oldIndex, 1)[0]);
157+
}
158+
},
152159
getUnderlyingVm: function getUnderlyingVm(htmlElt) {
153160
var index = computeVmIndex(this.getChildrenNodes(), htmlElt);
154161
var element = this.list[index];
@@ -212,7 +219,7 @@
212219
insertNodeAt(evt.from, evt.item, evt.oldIndex);
213220
var oldIndexVM = this.context.index;
214221
var newIndexVM = this.visibleIndexes[evt.newIndex];
215-
updatePosition(this.list, oldIndexVM, newIndexVM);
222+
this.updatePosition(oldIndexVM, newIndexVM);
216223
},
217224
onDragMove: function onDragMove(evt) {
218225
var onMove = this.move;
@@ -233,7 +240,7 @@
233240
return draggableComponent;
234241
}
235242

236-
if (typeof exports == "object") {
243+
if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) == "object") {
237244
var Sortable = require("sortablejs");
238245
module.exports = buildDraggable(Sortable);
239246
} else if (typeof define == "function" && define.amd) {

dist/vuedraggable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vuedraggable.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
return vnodes.map(elt => elt.elm).indexOf(element)
1919
}
2020

21-
function updatePosition (collection, oldIndex, newIndex) {
22-
if (collection) {
23-
collection.splice(newIndex, 0, collection.splice(oldIndex, 1)[0])
24-
}
25-
}
26-
2721
function computeIndexes (slots, children) {
2822
return (!slots)? [] : Array.prototype.map.call(children, elt => computeVmIndex(slots, elt))
2923
}
@@ -150,6 +144,14 @@
150144
return __vue__.$parent
151145
},
152146

147+
spliceList () {
148+
this.list.splice(...arguments)
149+
},
150+
151+
updatePosition (oldIndex, newIndex) {
152+
this.list.splice(newIndex, 0, this.list.splice(oldIndex, 1)[0])
153+
},
154+
153155
getRelatedContextFromMoveEvent({to, related}) {
154156
const component = this.getUnderlyingPotencialDraggableComponent(to)
155157
if (!component) {
@@ -180,7 +182,7 @@
180182
const domNewIndex = evt.newIndex
181183
const numberIndexes = indexes.length
182184
const newIndex = (domNewIndex > numberIndexes - 1) ? numberIndexes : indexes[domNewIndex]
183-
this.list.splice(newIndex, 0, element)
185+
this.spliceList(newIndex, 0, element)
184186
this.computeIndexes()
185187
},
186188

@@ -192,15 +194,15 @@
192194
return
193195
}
194196
const oldIndex = this.context.index
195-
this.list.splice(oldIndex, 1)
197+
this.spliceList(oldIndex, 1)
196198
},
197199

198200
onDragUpdate (evt) {
199201
removeNode(evt.item)
200202
insertNodeAt(evt.from, evt.item, evt.oldIndex)
201203
const oldIndexVM = this.context.index
202204
const newIndexVM = this.visibleIndexes[evt.newIndex]
203-
updatePosition(this.list, oldIndexVM, newIndexVM)
205+
this.updatePosition(oldIndexVM, newIndexVM)
204206
},
205207

206208
onDragMove (evt) {

0 commit comments

Comments
 (0)