Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
feat(dialog): Use MutationObserver for reactive slot updates (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
matsp committed Apr 23, 2018
1 parent cfbf749 commit d6278b5
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions components/dialog/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default {
},
data () {
return {
mdcDialog: null
mdcDialog: null,
slotOberserver: null
}
},
computed: {
Expand All @@ -75,32 +76,38 @@ export default {
}
},
mounted () {
let vm = this
this.updateSlots()
this.slotOberserver = new MutationObserver( () => this.updateSlots())
this.slotOberserver.observe(this.$el, {
childList: true,
subtree: true
})
if (vm.$slots.acceptButton) {
vm.$slots.acceptButton.map(n => {
n.elm.classList.add('mdc-dialog__footer__button')
n.elm.classList.add('mdc-dialog__footer__button--accept')
})
}
if (vm.$slots.cancelButton) {
vm.$slots.cancelButton.map(n => {
n.elm.classList.add('mdc-dialog__footer__button')
n.elm.classList.add('mdc-dialog__footer__button--cancel')
})
}
if (vm.$slots.dialogButton) {
vm.$slots.dialogButton.map(n => {
n.elm.classList.add('mdc-dialog__footer__button')
})
}
vm.mdcDialog = MDCDialog.attachTo(this.$el)
this.mdcDialog = MDCDialog.attachTo(this.$el)
},
beforeDestroy () {
this.mdcDialog.destroy()
},
methods: {
updateSlots () {
if (this.$slots.acceptButton) {
this.$slots.acceptButton.map(n => {
n.elm.classList.add('mdc-dialog__footer__button')
n.elm.classList.add('mdc-dialog__footer__button--accept')
})
}
if (this.$slots.cancelButton) {
this.$slots.cancelButton.map(n => {
n.elm.classList.add('mdc-dialog__footer__button')
n.elm.classList.add('mdc-dialog__footer__button--cancel')
})
}
if (this.$slots.dialogButton) {
this.$slots.dialogButton.map(n => {
n.elm.classList.add('mdc-dialog__footer__button')
})
}
},
onAccept () {
this.model = false
this.$emit('accept')
Expand Down

0 comments on commit d6278b5

Please sign in to comment.