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

Commit

Permalink
feat(list): 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 4dc7e4b commit 64c382d
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions components/list/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default {
},
data () {
return {
mdcRipple: null
mdcRipple: null,
slotOberserver: null
}
},
computed: {
Expand All @@ -58,21 +59,32 @@ export default {
}
},
mounted () {
this.updateSlots()
this.slotOberserver = new MutationObserver( () => this.updateSlots())
this.slotOberserver.observe(this.$el, {
childList: true,
subtree: true
})
if (this.interactive) { this.mdcRipple = MDCRipple.attachTo(this.$el) }
if (this.$slots.graphic) {
this.$slots.graphic.map(n => {
n.elm.classList.add('mdc-list-item__graphic')
})
}
if (this.$slots.meta) {
this.$slots.meta.map(n => {
n.elm.classList.add('mdc-list-item__meta')
})
}
},
beforeDestroy () {
this.slotOberserver.disconnect()
if (this.interactive) { this.mdcRipple.destroy() }
},
methods: {
updateSlots () {
if (this.$slots.graphic) {
this.$slots.graphic.map(n => {
n.elm.classList.add('mdc-list-item__graphic')
})
}
if (this.$slots.meta) {
this.$slots.meta.map(n => {
n.elm.classList.add('mdc-list-item__meta')
})
}
}
}
}
</script>

0 comments on commit 64c382d

Please sign in to comment.