chore(lazyload): remove some legecy code (#8650)

This commit is contained in:
neverland 2021-05-02 11:49:32 +08:00 committed by GitHub
parent 819018ef68
commit 721ecb6e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 36 deletions

View File

@ -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 = [];
} }

View File

@ -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);
} }

View File

@ -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,

View File

@ -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,