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

Commit

Permalink
feat(button): 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 6afa4e9 commit b115d8f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions components/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default {
},
data () {
return {
mdcRipple: null
mdcRipple: null,
slotOberserver: null
}
},
computed: {
Expand All @@ -69,16 +70,27 @@ export default {
}
},
mounted () {
if (this.$slots.icon) {
this.$slots.icon.map(n => {
n.elm.classList.add('mdc-button__icon')
})
}
this.updateSlot()
this.slotOberserver = new MutationObserver( () => this.updateSlot())
this.slotOberserver.observe(this.$el, {
childList: true,
subtree: true
})
if (this.interactive) { this.mdcRipple = MDCRipple.attachTo(this.$el) }
},
beforeDestroy () {
this.slotOberserver.disconnect()
if (this.interactive) { this.mdcRipple.destroy() }
},
methods: {
updateSlot() {
if (this.$slots.icon) {
this.$slots.icon.map(n => {
n.elm.classList.add('mdc-button__icon')
})
}
}
}
}
</script>

0 comments on commit b115d8f

Please sign in to comment.