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

Commit

Permalink
feat(top-app-bar): 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 e1221c5 commit 9a13f7e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions components/top-app-bar/TopAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default {
},
data () {
return {
mdcTopAppBar: undefined
mdcTopAppBar: undefined,
slotObserver: undefined
}
},
computed: {
Expand All @@ -65,24 +66,32 @@ export default {
}
},
mounted () {
if (this.$slots.navigation) {
this.$slots.navigation.map(n => {
n.elm.classList.add('mdc-top-app-bar__navigation-icon')
})
}
if (this.$slots.actions) {
this.$slots.actions.map(n => {
n.elm.classList.add('mdc-top-app-bar__action-item')
})
}
this.updateSlots()
this.slotObserver = new MutationObserver( () => this.updateSlots())
this.slotObserver.observe(this.$el, {
childList: true,
subtree: true
})
this.mdcTopAppBar = MDCTopAppBar.attachTo(this.$el)
},
beforeDestroy () {
this.slotObserver.disconnect()
this.mdcTopAppBar.destroy()
},
methods: {
updateSlots () {
if (this.$slots.navigation) {
this.$slots.navigation.map(n => {
n.elm.classList.add('mdc-top-app-bar__navigation-icon')
})
}
if (this.$slots.actions) {
this.$slots.actions.map(n => {
n.elm.classList.add('mdc-top-app-bar__action-item')
})
}
},
onNavigation () {
this.$emit('onNavigation')
}
Expand Down

0 comments on commit 9a13f7e

Please sign in to comment.