Skip to content

Commit

Permalink
fix multiple resize requests clashing
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Jan 11, 2023
1 parent 90ea674 commit c9adc4a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface CalendarState {
export default class FullCalendar extends Component<CalendarOptions, CalendarState> {
private elRef = createRef<HTMLDivElement>()
private calendar: Calendar
private needCustomRenderingResize = false
private needsCustomRenderingResize = false

state: CalendarState = {
customRenderingMap: new Map<string, CustomRendering<any>>()
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class FullCalendar extends Component<CalendarOptions, CalendarSta

this.calendar.render()
customRenderingStore.subscribe((customRenderingMap) => {
this.needCustomRenderingResize = true
this.needsCustomRenderingResize = true
this.setState({ customRenderingMap })
})
}
Expand All @@ -75,12 +75,16 @@ export default class FullCalendar extends Component<CalendarOptions, CalendarSta
}, true)
}

if (this.needCustomRenderingResize) {
this.needCustomRenderingResize = false
this.calendar.updateSize()
if (this.needsCustomRenderingResize) {
this.needsCustomRenderingResize = false
this.requestCustomRenderingResize()
}
}

requestCustomRenderingResize = debounce(() => {
this.calendar.updateSize()
})

componentWillUnmount() {
this.calendar.destroy()
}
Expand All @@ -105,3 +109,13 @@ function computeUpdates(origObj: any, newObj: any): any {

return updates
}

function debounce(func: any){
let timer: number
return (...args: any[]) => {
clearTimeout(timer)
timer = setTimeout(() => {
func.apply(this, args)
})
};
}

0 comments on commit c9adc4a

Please sign in to comment.