Skip to content

Commit

Permalink
fix(v-item-group): handle initial item state on registration
Browse files Browse the repository at this point in the history
avoid unnecessary update of items state, handle explicitly on registration if needed

fixes #5410
  • Loading branch information
johnleider committed Oct 24, 2018
1 parent 88f3749 commit 4af99de
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
9 changes: 4 additions & 5 deletions src/components/VCarousel/VCarousel.ts
Expand Up @@ -83,6 +83,10 @@ export default VWindow.extend({
}
},

mounted () {
this.startTimeout()
},

methods: {
genDelimiters (): VNode {
return this.$createElement('div', {
Expand Down Expand Up @@ -164,11 +168,6 @@ export default VWindow.extend({
}
}, children)
},
init () {
VWindow.options.methods.init.call(this)

this.startTimeout()
},
restartTimeout () {
this.slideTimeout && clearTimeout(this.slideTimeout)
this.slideTimeout = undefined
Expand Down
14 changes: 7 additions & 7 deletions src/components/VItemGroup/VItemGroup.ts
Expand Up @@ -89,19 +89,12 @@ export const BaseItemGroup = mixins(
}
},

mounted () {
this.$nextTick(this.init)
},

methods: {
getValue (item: GroupableInstance, i: number): unknown {
return item.value == null || item.value === ''
? i
: item.value
},
init () {
this.updateItemsState()
},
onClick (item: GroupableInstance, index: number) {
this.updateInternalValue(
this.getValue(item, index)
Expand All @@ -111,6 +104,13 @@ export const BaseItemGroup = mixins(
const index = this.items.push(item) - 1

item.$on('change', () => this.onClick(item, index))

// If no value provided and mandatory,
// assign first registered item
if (this.mandatory && this.internalLazyValue == null) {
this.updateMandatory()
}

this.updateItem(item, index)
},
unregister (item: GroupableInstance) {
Expand Down
10 changes: 4 additions & 6 deletions src/components/VWindow/VWindow.ts
Expand Up @@ -75,6 +75,10 @@ export default BaseItemGroup.extend({
internalIndex: 'updateReverse'
},

mounted () {
this.$nextTick(() => (this.isBooted = true))
},

methods: {
genContainer (): VNode {
return this.$createElement('div', {
Expand All @@ -87,12 +91,6 @@ export default BaseItemGroup.extend({
}
}, this.$slots.default)
},
init () {
BaseItemGroup.options.methods.init.call(this)

// Ensure no entry animation
this.$nextTick(() => (this.isBooted = true))
},
next () {
this.isReverse = false
const nextIndex = (this.internalIndex + 1) % this.items.length
Expand Down
Expand Up @@ -160,9 +160,7 @@ exports[`VCarousel.ts should render component with custom icon and match snapsho
</div>
</div>
<div class="v-window__container">
<div class="v-window-item v-window-x-transition-enter v-window-x-transition-enter-active"
style
>
<div class="v-window-item">
<div class="v-responsive v-image v-carousel__item"
style="height: 500px;"
>
Expand Down Expand Up @@ -465,9 +463,7 @@ exports[`VCarousel.ts should render component without delimiters 1`] = `
</button>
</div>
<div class="v-window__container">
<div class="v-window-item v-window-x-transition-enter v-window-x-transition-enter-active"
style
>
<div class="v-window-item">
<div class="v-responsive v-image v-carousel__item"
style="height: 500px;"
>
Expand Down
4 changes: 2 additions & 2 deletions test/unit/components/VWindow/VWindow.spec.js
Expand Up @@ -5,8 +5,8 @@ import { test, touch } from '@/test'
test('VWindow.ts', ({ mount }) => {
it('it should return the correct transition', async () => {
const wrapper = mount(VWindow)
// Wait for booted
await wrapper.vm.$nextTick()
// Force booted
wrapper.setData({ isBooted: true })

expect(wrapper.vm.computedTransition).toBe('v-window-x-transition')

Expand Down

0 comments on commit 4af99de

Please sign in to comment.