Commit 3f073ea11fb89ac588e03450eec129c825ff6fcb
mapped-array: add onMove callback
Matt McKegg committed on 4/24/2017, 3:28:32 AMParent: 0439268600e5c3782ae500bd8b7b0f19b68ba382
Files changed
mapped-array.js | changed |
mapped-array.js | ||
---|---|---|
@@ -33,9 +33,9 @@ | ||
33 | 33 … | } |
34 | 34 … | |
35 | 35 … | obs.move = function (mappedItem, targetIndex) { |
36 | 36 … | var currentIndex = obs.indexOf(mappedItem) |
37 | - if (~currentIndex) { | |
37 … | + if (~currentIndex && currentIndex !== targetIndex) { | |
38 | 38 … | var item = list.get(currentIndex) |
39 | 39 … | if (currentIndex < targetIndex) { |
40 | 40 … | list.transaction(function () { |
41 | 41 … | list.insert(item, targetIndex + 1) |
@@ -46,8 +46,12 @@ | ||
46 | 46 … | list.insert(item, targetIndex) |
47 | 47 … | list.deleteAt(currentIndex + 1) |
48 | 48 … | }) |
49 | 49 … | } |
50 … | + | |
51 … | + if (typeof opts.onMove === 'function') { | |
52 … | + opts.onMove(mappedItem, currentIndex, targetIndex) | |
53 … | + } | |
50 | 54 … | } |
51 | 55 … | } |
52 | 56 … | |
53 | 57 … | return obs |
Built with git-ssb-web