Skip to content

Commit

Permalink
refactor: remove non-null assertions
Browse files Browse the repository at this point in the history
depends on vuejs/vue#9154
  • Loading branch information
KaelWD committed Dec 6, 2018
1 parent 3bf014c commit 36dd7ce
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VBadge/VBadge.ts
Expand Up @@ -59,7 +59,7 @@ export default mixins(
staticClass: 'v-badge',
'class': this.classes
}, [
this.$slots.default!,
this.$slots.default,
h('transition', {
props: {
name: this.transition,
Expand Down
34 changes: 15 additions & 19 deletions packages/vuetify/src/components/VBtn/VBtn.ts
Expand Up @@ -119,25 +119,19 @@ export default baseMixins.extend<options>().extend({
return this.$createElement(
'div',
{ 'class': 'v-btn__content' },
[this.$slots.default!]
this.$slots.default
)
},
genLoader (): VNode {
const children: VNodeChildren = []

if (!this.$slots.loader) {
children.push(this.$createElement(VProgressCircular, {
props: {
indeterminate: true,
size: 23,
width: 2
}
}))
} else {
children.push(this.$slots.loader)
}

return this.$createElement('span', { 'class': 'v-btn__loading' }, children)
return this.$createElement('span', {
class: 'v-btn__loading'
}, this.$slots.loader || [this.$createElement(VProgressCircular, {
props: {
indeterminate: true,
size: 23,
width: 2
}
})])
},
onRouteChange () {
if (!this.to || !this.$refs.link) return
Expand All @@ -155,10 +149,12 @@ export default baseMixins.extend<options>().extend({
render (h): VNode {
const setColor = (!this.outline && !this.flat && !this.disabled) ? this.setBackgroundColor : this.setTextColor
const { tag, data } = this.generateRouteLink(this.classes)
const children = [this.genContent()]
const children = [
this.genContent(),
this.loading && this.genLoader()
]

tag === 'button' && (data.attrs!.type = this.type)
this.loading && children.push(this.genLoader())
if (tag === 'button') data.attrs!.type = this.type

data.attrs!.value = ['string', 'number'].includes(typeof this.value)
? this.value
Expand Down
9 changes: 4 additions & 5 deletions packages/vuetify/src/components/VChip/VChip.ts
Expand Up @@ -63,13 +63,12 @@ export default mixins(Colorable, Themeable, Toggleable).extend({
])
},
genContent (h: CreateElement): VNode {
const children: VNodeChildren = [this.$slots.default!]

this.close && children.push(this.genClose(h))

return h('span', {
staticClass: 'v-chip__content'
}, children)
}, [
this.$slots.default,
this.close && this.genClose(h)
])
}
},

Expand Down
Expand Up @@ -142,11 +142,6 @@ export default mixins<options &
},

render (h): VNode {
const children = []

this.$slots.header && children.push(this.genHeader())
children.push(h(VExpandTransition, [this.genBody()]))

return h('li', {
staticClass: 'v-expansion-panel__container',
class: this.containerClasses,
Expand All @@ -156,6 +151,9 @@ export default mixins<options &
on: {
keydown: this.onKeydown
}
}, children)
}, [
this.$slots.header && this.genHeader(),
h(VExpandTransition, [this.genBody()])
])
}
})
Expand Up @@ -131,7 +131,7 @@ export default mixins(Colorable).extend({
},

render (h): VNode {
const info = h('div', { staticClass: 'v-progress-circular__info' }, [this.$slots.default!])
const info = h('div', { staticClass: 'v-progress-circular__info' }, this.$slots.default)
const svg = this.genSvg(h)

return h('div', this.setTextColor(this.color, {
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VRating/VRating.ts
Expand Up @@ -16,7 +16,7 @@ import { createRange } from '../../util/helpers'
import mixins from '../../util/mixins'

// Types
import { VNode, VNodeDirective, VNodeChildrenArrayContents } from 'vue'
import { VNode, VNodeDirective, VNodeChildren } from 'vue'

type ItemSlotProps = {
index: number
Expand Down Expand Up @@ -188,7 +188,7 @@ export default mixins(
onMouseLeave (): void {
this.runDelay('close', () => (this.hoverIndex = -1))
},
genItem (i: number): VNode | VNodeChildrenArrayContents | string {
genItem (i: number): VNode | VNodeChildren | string {
const props = this.createProps(i)

if (this.$scopedSlots.item) return this.$scopedSlots.item(props)
Expand Down
36 changes: 15 additions & 21 deletions packages/vuetify/src/components/VSnackbar/VSnackbar.ts
Expand Up @@ -71,28 +71,22 @@ export default mixins(
},

render (h): VNode {
const children: VNodeChildrenArrayContents = []

if (this.isActive) {
children.push(
h('div', {
staticClass: 'v-snack',
class: this.classes,
on: this.$listeners
}, [
h('div', this.setBackgroundColor(this.color, {
staticClass: 'v-snack__wrapper'
}), [
h('div', {
staticClass: 'v-snack__content'
}, this.$slots.default)
])
])
)
}

return h('transition', {
attrs: { name: 'v-snack-transition' }
}, children)
}, this.isActive && [
h('div', {
staticClass: 'v-snack',
class: this.classes,
on: this.$listeners
}, [
h('div', this.setBackgroundColor(this.color, {
staticClass: 'v-snack__wrapper'
}), [
h('div', {
staticClass: 'v-snack__content'
}, this.$slots.default)
])
])
])
}
})
8 changes: 2 additions & 6 deletions packages/vuetify/src/components/VTimeline/VTimelineItem.ts
Expand Up @@ -57,16 +57,12 @@ export default mixins(
}, this.icon)
},
genInnerDot () {
const children = []

this.hasIcon && children.push(this.genIcon())

const data: VNodeData = this.setBackgroundColor(this.color)

return this.$createElement('div', {
staticClass: 'v-timeline-item__inner-dot',
...data
}, children)
}, [this.hasIcon && this.genIcon()])
},
genDot () {
return this.$createElement('div', {
Expand All @@ -80,7 +76,7 @@ export default mixins(
genOpposite () {
return this.$createElement('div', {
staticClass: 'v-timeline-item__opposite'
}, [this.$slots.opposite!])
}, this.$slots.opposite)
}
},

Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VTreeview/VTreeview.ts
Expand Up @@ -327,7 +327,7 @@ export default mixins(
const children: VNodeChildrenArrayContents = this.items.length
? this.items.map(VTreeviewNode.options.methods.genChild.bind(this))
/* istanbul ignore next */
: this.$slots.default!
: this.$slots.default! // TODO: remove type annotation with TS 3.2

return h('div', {
staticClass: 'v-treeview',
Expand Down
5 changes: 2 additions & 3 deletions packages/vuetify/src/components/VTreeview/VTreeviewNode.ts
Expand Up @@ -162,11 +162,10 @@ export default mixins<options>(
}, [this.text])
},
genContent () {
// TODO: remove non-null assertions (vuejs/vue#8498)
const children = [
this.$scopedSlots.prepend! && this.$scopedSlots.prepend!(this.scopedProps),
this.$scopedSlots.prepend && this.$scopedSlots.prepend(this.scopedProps),
this.genLabel(),
this.$scopedSlots.append! && this.$scopedSlots.append!(this.scopedProps)
this.$scopedSlots.append && this.$scopedSlots.append(this.scopedProps)
]

return this.$createElement('div', {
Expand Down

0 comments on commit 36dd7ce

Please sign in to comment.