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

Commit

Permalink
feat(fab): 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 a4946c3 commit 3668145
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions components/fab/Fab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default {
},
data () {
return {
mdcRipple: null
mdcRipple: null,
slotOberserver: null
}
},
computed: {
Expand All @@ -47,16 +48,26 @@ export default {
}
},
mounted () {
if (this.$slots.default) {
this.$slots.default.map(n => {
n.elm.classList.add('mdc-fab__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 () {
if (this.interactive) { this.mdcRipple.destroy() }
},
methods: {
updateSlot () {
if (this.$slots.default) {
this.$slots.default.map(n => {
n.elm.classList.add('mdc-fab__icon')
})
}
}
}
}
</script>

0 comments on commit 3668145

Please sign in to comment.