-
Notifications
You must be signed in to change notification settings - Fork 69
WIP make example work with Vue 2.x #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Hitting all kinds of road blocks with current example. I decided to create a clean Vue2 app with using https://github.com/kristianmandrup/vue2-dragula-demo Please help make it work :) IT references my current refactor branch. Feel free to fork and patch as needed... |
I got my demo working :) Vue 2 with Dragula! Now we just need to integrate some smart handles!!! |
I was somehow still referencing the old version of
So this is related to the add (name, drake) {
console.log('Dragula: add', name)
let bag = this.find(name)
if (bag) {
throw new Error('Bag named: "' + name + '" already exists.')
} I tried to fix the <div class="wrapper">
<div class="container" v-dragula="colOne" bag="first-bag">
<div v-for="text in colOne" @click="onClick">{{text}} [click me]</div>
</div>
<div class="container" v-dragula="colTwo" bag="first-bag">
<div v-for="text in colTwo">
<span class="handle">+</span>
<span>{{text}}</text>
</div>
</div>
</div> But in this case it is not allowed. Beats me how to use these bags the right way :P <label>Copy between containers</label>
<div class="wrapper">
<div class="container" v-dragula="copyOne" bag="third-bag">
<div v-for="text in copyOne" track-by="$index">{{text}}</div>
</div>
<div class="container" v-dragula="copyTwo" bag="third-bag">
<div v-for="text in copyTwo" track-by="$index">{{text}}</div>
</div>
</div> But it turns out, it is caused by adding this this.$dragula.eventBus.$on(
'drag',
function (el, container) {
console.log('drag: ', el, container)
// el.className = el.className.replace('ex-moved', '')
}
) |
Perhaps the problem is more related to me not understanding the initiation and hot reload process!? So as I see it, there is only ONE export default function (Vue, options = {}) {
const service = new DragulaService(Vue) When we bind, we get the const bagName = vnode
? vnode.data.attrs.bag // Vue 2
: this.params.bag // Vue 1 We then lookup the bag in the service singleton const bag = service.find(name) and then we add, which of course causes conflict when we have two or more elements with the same bag attribute!!! so what is the correct way to configure this example!? service.add(name, drake)
service.handleModels(name, drake) |
Looks like the problem is that there is one global singleton service shared by the directive instances. |
I think I finally have a sufficient understanding of the main problems with the current design and how to fix it with a more "modular" redesign. Described this in Readme of demo app. Perhaps we could have an API where let customContainer = document.getElementById('left-container')
let serviceTwo = this.$dragula.create({
containers: ['colOne', 'colTwo', customContainer],
bags: ['second-bag']
}).on({
drop (el, container) {
console.log('drop: ', el, container)
}
...
})
let serviceThree = this.$dragula.create({
containers: ['copyOne'],
bags: ['third-bag']
}).on({
drop (el, container) {
console.log('drop: ', el, container)
}
...
}) In our directive,
We could have the element with the directive register with a console.log('can bind to $dragula', name, vnode.context.$dragula) |
Trying to add various extensions to make it more flexible dev branch it works and looks very good!!! |
Development
section in Readme on how to usenpm
scripts included.ready
Please help me out, I need this for Vue2 app!! :)