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

Commit

Permalink
feat(image-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 63ccb4a commit 4dc7e4b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions components/image-list/ImageListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,30 @@ export default {
default: true
}
},
data() {
return {
slotOberserver: null
}
},
mounted () {
if (this.$slots.image) {
this.$slots.image.map(n => {
n.elm.classList.add('mdc-image-list__image')
})
this.updateSlot ()
this.slotOberserver = new MutationObserver( () => this.updateSlot())
this.slotOberserver.observe(this.$el, {
childList: true,
subtree: true
})
},
methods: {
updateSlot () {
if (this.$slots.image) {
this.$slots.image.map(n => {
n.elm.classList.add('mdc-image-list__image')
})
}
}
},
beforeDestroy () {
this.slotOberserver.disconnect()
}
}
</script>

0 comments on commit 4dc7e4b

Please sign in to comment.