Skip to content

Commit

Permalink
fix: list object sync
Browse files Browse the repository at this point in the history
  • Loading branch information
林建辉 committed Apr 20, 2017
1 parent 9209d2b commit 73c3109
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 62 deletions.
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@
}, {
text: "Burlywood"
}]

}
},
mounted: function() {
/*this.$dragging.$setList('color', this.colors)
this.$watch('colors', function() {
this.$nextTick(function() {
this.$dragging.$setList('color', this.colors)
})
})*/
}
})
</script>
Expand Down
70 changes: 39 additions & 31 deletions lib/vue-dragging.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/vue-dragging.js.map

Large diffs are not rendered by default.

68 changes: 38 additions & 30 deletions vue-dragging.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,6 @@ class DragData {
return this.data[key]
}
}
const $dragging = {
listeners: {
dragged: [],
dragend: []
},
$on (event, func) {
this.listeners[event].push(func)
},
$once (event, func) {
const vm = this
function on () {
vm.$off(event, on)
func.apply(vm, arguments)
}
this.$on(event, on)
},
$off (event, func) {
if (!func) {
this.listeners[event] = []
return
}
this.listeners[event].$remove(func)
},
$emit (event, context) {
this.listeners[event].forEach(func => {
func(context)
})
}
}

const _ = {
on (el, type, fn) {
Expand Down Expand Up @@ -86,6 +57,39 @@ export default function (Vue, options) {
const isPreVue = Vue.version.split('.')[0] === '1'
const dragData = new DragData()

const $dragging = {
listeners: {
dragged: [],
dragend: []
},
$on (event, func) {
this.listeners[event].push(func)
},
$once (event, func) {
const vm = this
function on () {
vm.$off(event, on)
func.apply(vm, arguments)
}
this.$on(event, on)
},
$off (event, func) {
if (!func) {
this.listeners[event] = []
return
}
this.listeners[event].$remove(func)
},
$emit (event, context) {
this.listeners[event].forEach(func => {
func(context)
})
}/* ,
$setList(group, list) {
const DDD = dragData.new(group)
DDD.List = list
} */
}
function handleDragStart(e) {
const el = getBlockEl(e.target)
const key = el.getAttribute('drag_group')
Expand Down Expand Up @@ -252,10 +256,14 @@ export default function (Vue, options) {
update: function(el, binding) {
const DDD = dragData.new(binding.value.group)
const item = binding.value.item
const list = binding.value.list
const old_item = DDD.EL_MAP.get(el)
if (old_item !== item) {
if (item && old_item !== item) {
DDD.EL_MAP.set(el, item)
}
if (list && DDD.List !== list) {
DDD.List = list
}
},
unbind : removeDragItem
})
Expand Down

0 comments on commit 73c3109

Please sign in to comment.