Skip to content

Commit 81af858

Browse files
committed
perf: optimize load condition checking logic
1 parent 57c0fab commit 81af858

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/components/InfiniteLoading.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import config, {
5555
evt3rdArg, WARNINGS, STATUS, SLOT_STYLES,
5656
} from '../config';
5757
import {
58-
warn, throttleer, loopTracker, scrollBarStorage, kebabCase,
58+
warn, throttleer, loopTracker, scrollBarStorage, kebabCase, isVisible,
5959
} from '../utils';
6060
6161
export default {
@@ -125,7 +125,7 @@ export default {
125125
spinner: String,
126126
direction: {
127127
type: String,
128-
default: config.props.direction,
128+
default: 'bottom',
129129
},
130130
forceUseInfiniteWrapper: {
131131
type: [Boolean, String],
@@ -148,7 +148,7 @@ export default {
148148
149149
this.scrollHandler = function scrollHandlerOriginal(ev) {
150150
if (this.status === STATUS.READY) {
151-
if (ev && ev.constructor === Event) {
151+
if (ev && ev.constructor === Event && isVisible(this.$el)) {
152152
throttleer.throttle(this.attemptLoad);
153153
} else {
154154
this.attemptLoad();
@@ -254,12 +254,10 @@ export default {
254254
* event handler
255255
*/
256256
attemptLoad(isContinuousCall) {
257-
const currentDistance = this.getCurrentDistance();
258-
259257
if (
260258
this.status !== STATUS.COMPLETE
261-
&& currentDistance <= this.distance
262-
&& (this.$el.offsetWidth + this.$el.offsetHeight) > 0
259+
&& isVisible(this.$el)
260+
&& this.getCurrentDistance() <= this.distance
263261
) {
264262
this.status = STATUS.LOADING;
265263

src/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,21 @@ export function kebabCase(str) {
111111
return str.replace(/[A-Z]/g, s => `-${s.toLowerCase()}`);
112112
}
113113

114+
/**
115+
* get visibility for element
116+
* @param {DOM} elm
117+
* @return {Boolean}
118+
*/
119+
export function isVisible(elm) {
120+
return (elm.offsetWidth + elm.offsetHeight) > 0;
121+
}
122+
114123
export default {
115124
warn,
116125
error,
117126
throttleer,
118127
loopTracker,
119128
kebabCase,
120129
scrollBarStorage,
130+
isVisible,
121131
};

0 commit comments

Comments
 (0)