git ssb

1+

Matt McKegg / mutant



Commit 3f073ea11fb89ac588e03450eec129c825ff6fcb

mapped-array: add onMove callback

Matt McKegg committed on 4/24/2017, 3:28:32 AM
Parent: 0439268600e5c3782ae500bd8b7b0f19b68ba382

Files changed

mapped-array.jschanged
mapped-array.jsView
@@ -33,9 +33,9 @@
3333 }
3434
3535 obs.move = function (mappedItem, targetIndex) {
3636 var currentIndex = obs.indexOf(mappedItem)
37- if (~currentIndex) {
37 + if (~currentIndex && currentIndex !== targetIndex) {
3838 var item = list.get(currentIndex)
3939 if (currentIndex < targetIndex) {
4040 list.transaction(function () {
4141 list.insert(item, targetIndex + 1)
@@ -46,8 +46,12 @@
4646 list.insert(item, targetIndex)
4747 list.deleteAt(currentIndex + 1)
4848 })
4949 }
50 +
51 + if (typeof opts.onMove === 'function') {
52 + opts.onMove(mappedItem, currentIndex, targetIndex)
53 + }
5054 }
5155 }
5256
5357 return obs

Built with git-ssb-web