mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(lazyload): remove some legecy code (#8650)
This commit is contained in:
parent
819018ef68
commit
721ecb6e76
@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable max-classes-per-file */
|
/* eslint-disable max-classes-per-file */
|
||||||
import { find, remove, ArrayFrom } from './util';
|
import { find, remove } from './util';
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
selector: 'img',
|
selector: 'img',
|
||||||
@ -44,7 +44,7 @@ class LazyContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getImgs() {
|
getImgs() {
|
||||||
return ArrayFrom(this.el.querySelectorAll(this.options.selector));
|
return Array.from(this.el.querySelectorAll(this.options.selector));
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
@ -57,10 +57,9 @@ class LazyContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LazyContainerMananger {
|
export default class LazyContainerManager {
|
||||||
constructor({ lazy }) {
|
constructor({ lazy }) {
|
||||||
this.lazy = lazy;
|
this.lazy = lazy;
|
||||||
lazy.lazyContainerMananger = this;
|
|
||||||
this._queue = [];
|
this._queue = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import {
|
|||||||
inBrowser,
|
inBrowser,
|
||||||
CustomEvent,
|
CustomEvent,
|
||||||
remove,
|
remove,
|
||||||
some,
|
|
||||||
find,
|
find,
|
||||||
_,
|
_,
|
||||||
throttle,
|
throttle,
|
||||||
@ -52,7 +51,6 @@ export default function () {
|
|||||||
observer,
|
observer,
|
||||||
observerOptions,
|
observerOptions,
|
||||||
}) {
|
}) {
|
||||||
this.version = '__VUE_LAZYLOAD_VERSION__';
|
|
||||||
this.mode = modeType.event;
|
this.mode = modeType.event;
|
||||||
this.ListenerQueue = [];
|
this.ListenerQueue = [];
|
||||||
this.TargetIndex = 0;
|
this.TargetIndex = 0;
|
||||||
@ -126,7 +124,7 @@ export default function () {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
add(el, binding, vnode) {
|
add(el, binding, vnode) {
|
||||||
if (some(this.ListenerQueue, (item) => item.el === el)) {
|
if (this.ListenerQueue.some((item) => item.el === el)) {
|
||||||
this.update(el, binding);
|
this.update(el, binding);
|
||||||
return nextTick(this.lazyLoadHandler);
|
return nextTick(this.lazyLoadHandler);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
import { loadImageAsync, noop } from './util';
|
import { loadImageAsync, noop } from './util';
|
||||||
|
|
||||||
// el: {
|
|
||||||
// state,
|
|
||||||
// src,
|
|
||||||
// error,
|
|
||||||
// loading
|
|
||||||
// }
|
|
||||||
|
|
||||||
export default class ReactiveListener {
|
export default class ReactiveListener {
|
||||||
constructor({
|
constructor({
|
||||||
el,
|
el,
|
||||||
|
@ -57,17 +57,6 @@ function remove(arr, item) {
|
|||||||
if (index > -1) return arr.splice(index, 1);
|
if (index > -1) return arr.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function some(arr, fn) {
|
|
||||||
let has = false;
|
|
||||||
for (let i = 0, len = arr.length; i < len; i++) {
|
|
||||||
if (fn(arr[i])) {
|
|
||||||
has = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return has;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBestSelectionFromSrcset(el, scale) {
|
function getBestSelectionFromSrcset(el, scale) {
|
||||||
if (el.tagName !== 'IMG' || !el.getAttribute('data-srcset')) return;
|
if (el.tagName !== 'IMG' || !el.getAttribute('data-srcset')) return;
|
||||||
|
|
||||||
@ -290,15 +279,6 @@ function isObject(obj) {
|
|||||||
return obj !== null && typeof obj === 'object';
|
return obj !== null && typeof obj === 'object';
|
||||||
}
|
}
|
||||||
|
|
||||||
function ArrayFrom(arrLike) {
|
|
||||||
const len = arrLike.length;
|
|
||||||
const list = [];
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
list.push(arrLike[i]);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
class ImageCache {
|
class ImageCache {
|
||||||
@ -331,10 +311,8 @@ export {
|
|||||||
inBrowser,
|
inBrowser,
|
||||||
CustomEvent,
|
CustomEvent,
|
||||||
remove,
|
remove,
|
||||||
some,
|
|
||||||
find,
|
find,
|
||||||
noop,
|
noop,
|
||||||
ArrayFrom,
|
|
||||||
_,
|
_,
|
||||||
isObject,
|
isObject,
|
||||||
throttle,
|
throttle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user