Skip to content

Commit

Permalink
klicker: Fix resizeobserver loop limit exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
schneefux committed Jan 19, 2024
1 parent 7b191d0 commit 31a070c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
40 changes: 19 additions & 21 deletions klicker/components/ui/b-scrolling-dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,26 @@ export default defineComponent({
const arrivedLeft = ref<boolean>(true)
const arrivedRight = ref<boolean>(true)
const onUpdate = (cause: 'scroll'|'rerender') => {
requestAnimationFrame(() => {
if (cause == 'scroll') {
emit(cause, {
x: scroll.x.value,
arrivedLeft: scroll.arrivedState.left,
arrivedRight: scroll.arrivedState.right,
})
}
if (cause == 'rerender') {
emit(cause, {
x: scroll.x.value,
arrivedLeft: scroll.arrivedState.left,
arrivedRight: scroll.arrivedState.right,
})
}
const onUpdate = (cause: 'scroll'|'rerender') => requestAnimationFrame(() => {
if (cause == 'scroll') {
emit(cause, {
x: scroll.x.value,
arrivedLeft: scroll.arrivedState.left,
arrivedRight: scroll.arrivedState.right,
})
}
if (cause == 'rerender') {
emit(cause, {
x: scroll.x.value,
arrivedLeft: scroll.arrivedState.left,
arrivedRight: scroll.arrivedState.right,
})
}
const scrollable = wrapper.value != undefined && wrapper.value.scrollWidth > wrapper.value.clientWidth
arrivedLeft.value = scroll.arrivedState.left || !scrollable
arrivedRight.value = scroll.arrivedState.right || !scrollable
})
}
const scrollable = wrapper.value != undefined && wrapper.value.scrollWidth > wrapper.value.clientWidth
arrivedLeft.value = scroll.arrivedState.left || !scrollable
arrivedRight.value = scroll.arrivedState.right || !scrollable
})
const scroll = useScroll(wrapper, {
onScroll: () => onUpdate('scroll'),
Expand Down
2 changes: 1 addition & 1 deletion klicker/components/ui/b-vega.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</template>

<script lang="ts">
import embed, { Result, VisualizationSpec } from 'vega-embed'
import embed, { VisualizationSpec } from 'vega-embed'
import Fa from '../fa.vue'
import { faDownload } from '@fortawesome/free-solid-svg-icons'
import BShimmer from './b-shimmer.vue'
Expand Down
4 changes: 2 additions & 2 deletions klicker/components/visualisations/v-barplot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ export default defineComponent({
const pageSize = ref(values.value.length)
const wrapper = ref<HTMLElement>()
useResizeObserver(wrapper, ([ entry ]) => {
useResizeObserver(wrapper, ([ entry ]) => window.requestAnimationFrame(() => {
if (wrapper.value == undefined) {
return
}
const pxAvailableWidth = entry.contentRect.width - 100
const pxPerBar = 12
pageSize.value = Math.min(Math.max(Math.floor(pxAvailableWidth / pxPerBar), 1), values.value.length)
})
}))
return {
wrapper,
Expand Down
4 changes: 2 additions & 2 deletions klicker/components/visualisations/v-roll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default defineComponent({
nextTick(() => pageSize.value = calculatePageSize())
}
useResizeObserver(wrapper, ([ entry ]) => {
useResizeObserver(wrapper, ([ entry ]) => window.requestAnimationFrame(() => {
if (wrapper.value == undefined) {
return
}
Expand All @@ -189,7 +189,7 @@ export default defineComponent({
pxPreviousWidth.value = pxWholeWidth
updatePageSize()
})
}))
const previousItemsLength = ref(body.value.length)
watch(() => body.value, () => {
Expand Down

0 comments on commit 31a070c

Please sign in to comment.