Skip to content

Commit

Permalink
fix: bug with unstoppable loader triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
gavrashenko committed Oct 8, 2021
1 parent 6b79452 commit 1cdadc0
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 57 deletions.
37 changes: 21 additions & 16 deletions dist/vue-eternal-loading.common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-eternal-loading.common.js.map

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions dist/vue-eternal-loading.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-eternal-loading.umd.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/vue-eternal-loading.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-eternal-loading.umd.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ts-pro/vue-eternal-loading",
"description": "Infinity loading component vue3 projects.",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/vue-eternal-loading.common.js",
"types": "./src/main.ts",
"exports": {
Expand Down
24 changes: 19 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<template>
<button @click="reset">Reset list</button>
<div v-for="(item, index) in items" :key="index" class="item">
page {{ parseInt(index / 10) + 1 }} | {{ item }}
<div class="box" ref="boxRef">
<button @click="reset">Reset list</button>
<div v-for="(item, index) in items" :key="index" class="item">
page {{ parseInt(index / 10) + 1 }} | {{ item }}
</div>
<VueEternalLoading
v-model:is-initial="isInitial"
:load="load"
:container="boxRef"
>
</VueEternalLoading>
</div>
<VueEternalLoading v-model:is-initial="isInitial" :load="load">
</VueEternalLoading>
</template>

<script lang="ts">
Expand All @@ -21,6 +27,7 @@ export default defineComponent({
setup() {
const items = ref<string[]>([]);
const isInitial = ref(true);
const boxRef = ref<HTMLElement | null>(null);
let page = 1;
function load({ loaded, noMore }: LoadAction) {
Expand Down Expand Up @@ -62,6 +69,7 @@ export default defineComponent({
items,
isInitial,
reset,
boxRef,
};
},
});
Expand All @@ -77,4 +85,10 @@ button {
padding: 5px;
background-color: #ccc;
}
.box {
width: 500px;
height: 500px;
outline: 1px solid black;
overflow: scroll;
}
</style>
27 changes: 13 additions & 14 deletions src/components/VueEternalLoading/VueEternalLoading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default defineComponent({
container: {
required: false,
type: Object as PropType<HTMLElement | null>,
default: document.documentElement,
default: null,
},
margin: {
required: false,
Expand All @@ -80,12 +80,12 @@ export default defineComponent({
nextTick(() => {
if (props.position === 'top') {
restoreScrollVerticalPosition(
props.container as HTMLElement,
props.container ?? document.documentElement,
scrollSize
);
} else if (props.position === 'left') {
restoreScrollHorizontalPosition(
props.container as HTMLElement,
props.container ?? document.documentElement,
scrollSize
);
}
Expand Down Expand Up @@ -163,10 +163,12 @@ export default defineComponent({
if (entry.isIntersecting) {
if (props.position === 'top') {
scrollSize = getScrollHeightFromEl(
props.container as HTMLElement
props.container ?? document.documentElement
);
} else if (props.position === 'left') {
scrollSize = getScrollWidthFromEl(props.container as HTMLElement);
scrollSize = getScrollWidthFromEl(
props.container ?? document.documentElement
);
}
unobserve();
props.load(
Expand All @@ -193,16 +195,13 @@ export default defineComponent({
let observer: IntersectionObserver;
watchEffect(
() => {
// Container can be null for the first `mount` if we pass here parent's `ref`.
if (props.container !== null) {
// Stop old observer if it exists
if (observer) {
unobserve();
}
observer = createObserver();
observe();
// Stop old observer if it exists
if (observer) {
unobserve();
}
observer = createObserver();
observe();
},
{
flush: 'post',
Expand Down

0 comments on commit 1cdadc0

Please sign in to comment.