Skip to content

Commit

Permalink
Merge pull request #430 from ismail9k/383-hot-reloading-not-working
Browse files Browse the repository at this point in the history
fix(carousel): dynamically recalculate slots in render function
  • Loading branch information
ismail9k authored Nov 27, 2024
2 parents 10f4a19 + 5711457 commit 8a9e2e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/components/Carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

import { DEFAULT_CONFIG } from '@/partials/defaults'
import { carouselProps } from '@/partials/props'
import { CarouselConfig, CarouselExposed, CarouselNav } from '@/types'
import { CarouselConfig, CarouselData, CarouselExposed, CarouselNav } from '@/types'
import {
debounce,
throttle,
Expand Down Expand Up @@ -411,15 +411,15 @@ export default defineComponent({
// Init carousel
emit('before-init')

const data = {
const data = reactive<CarouselData>({
config,
slidesCount,
slideSize,
currentSlide: currentSlideIndex,
maxSlide: maxSlideIndex,
minSlide: minSlideIndex,
middleSlide: middleSlideIndex,
}
})

expose<CarouselExposed>({
updateBreakpointsConfig,
Expand Down Expand Up @@ -462,11 +462,10 @@ export default defineComponent({
return `translate${translateAxis}(${dragOffset - totalOffset}px)`
})

const slotSlides = slots.default || slots.slides
const slotAddons = slots.addons
const slotsProps = reactive(data)

return () => {
const slotSlides = slots.default || slots.slides
const slotAddons = slots.addons

if (!config.enabled) {
return h(
'section',
Expand All @@ -478,8 +477,9 @@ export default defineComponent({
)
}

const slidesElements = getSlidesVNodes(slotSlides?.(slotsProps))
const addonsElements = slotAddons?.(slotsProps) || []
const slidesElements = getSlidesVNodes(slotSlides?.(data))
const addonsElements = slotAddons?.(data) || []

slidesElements.forEach((el: typeof SlideComponent, index: number) => {
if (el.props) {
el.props.index = index
Expand Down
4 changes: 2 additions & 2 deletions src/types/carousel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ref } from 'vue'
import { Reactive, Ref } from 'vue'

import {
BREAKPOINT_MODE_OPTIONS,
Expand Down Expand Up @@ -60,5 +60,5 @@ export interface CarouselMethods extends CarouselNav {
}
export interface CarouselExposed extends CarouselMethods {
nav: CarouselNav
data: CarouselData
data: Reactive<CarouselData>
}

0 comments on commit 8a9e2e1

Please sign in to comment.