Skip to content

Commit

Permalink
Merge pull request #23 from AmazingDreams/master
Browse files Browse the repository at this point in the history
Callbacks through emit
  • Loading branch information
Wlada committed May 12, 2017
2 parents e2f0767 + e0e490f commit 824c318
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
31 changes: 31 additions & 0 deletions play/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,34 @@ play('Carousel3d', module)
}
}
})

.add("callbacks through emit", {
template: `<carousel-3d
@afterSlideChanged="onAfterSlideChanged"
@lastSlide="onLastSlide"
@slideChange="onSlideChange">
<slide v-for="(slide, i) in slides" :index="i">
<img :src="slide.src">
</slide>
</carousel-3d>`,
components: {
Carousel3d,
Slide
},
data() {
return {
slides: slides
}
},
methods: {
onAfterSlideChanged(index){
console.log('@afterSlideChanged Callback Triggered', 'Slide Index ' + index)
},
onSlideChange(index){
console.log('@slideChange Callback Triggered', 'Slide Index ' + index)
},
onLastSlide(index){
console.log('@lastSlide Callback Triggered', 'Slide Index ' + index)
}
}
})
13 changes: 13 additions & 0 deletions src/Carousel3d.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,16 @@
this.lock = true
if (this.isLastSlide) {
if (this.onLastSlide !== noop) {
console.warn('onLastSlide deprecated, please use @lastSlide')
}
this.onLastSlide(this.currentIndex)
this.$emit('lastSlide', this.currentIndex)
}
this.$emit('slideChange', this.currentIndex)
setTimeout(() => this.animationEnd(), this.animationSpeed)
},
/**
Expand Down Expand Up @@ -240,7 +247,13 @@
*/
animationEnd () {
this.lock = false
if (this.onSlideChange !== noop) {
console.warn('onSlideChange deprecated, please use @afterSlideChanged')
}
this.onSlideChange(this.currentIndex)
this.$emit('afterSlideChanged', this.currentIndex)
},
/**
* Trigger actions when mouse is released
Expand Down

0 comments on commit 824c318

Please sign in to comment.