From 721ecb6e764ce42c7192b9c7b82df75c81096de6 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 2 May 2021 11:49:32 +0800 Subject: [PATCH] chore(lazyload): remove some legecy code (#8650) --- packages/vant-lazyload/src/lazy-container.js | 7 +++---- packages/vant-lazyload/src/lazy.js | 4 +--- packages/vant-lazyload/src/listener.js | 7 ------- packages/vant-lazyload/src/util.js | 22 -------------------- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/packages/vant-lazyload/src/lazy-container.js b/packages/vant-lazyload/src/lazy-container.js index f0518e284..f795e0af7 100644 --- a/packages/vant-lazyload/src/lazy-container.js +++ b/packages/vant-lazyload/src/lazy-container.js @@ -1,5 +1,5 @@ /* eslint-disable max-classes-per-file */ -import { find, remove, ArrayFrom } from './util'; +import { find, remove } from './util'; const defaultOptions = { selector: 'img', @@ -44,7 +44,7 @@ class LazyContainer { } getImgs() { - return ArrayFrom(this.el.querySelectorAll(this.options.selector)); + return Array.from(this.el.querySelectorAll(this.options.selector)); } clear() { @@ -57,10 +57,9 @@ class LazyContainer { } } -export default class LazyContainerMananger { +export default class LazyContainerManager { constructor({ lazy }) { this.lazy = lazy; - lazy.lazyContainerMananger = this; this._queue = []; } diff --git a/packages/vant-lazyload/src/lazy.js b/packages/vant-lazyload/src/lazy.js index debd573c2..d91e14122 100644 --- a/packages/vant-lazyload/src/lazy.js +++ b/packages/vant-lazyload/src/lazy.js @@ -3,7 +3,6 @@ import { inBrowser, CustomEvent, remove, - some, find, _, throttle, @@ -52,7 +51,6 @@ export default function () { observer, observerOptions, }) { - this.version = '__VUE_LAZYLOAD_VERSION__'; this.mode = modeType.event; this.ListenerQueue = []; this.TargetIndex = 0; @@ -126,7 +124,7 @@ export default function () { * @return */ add(el, binding, vnode) { - if (some(this.ListenerQueue, (item) => item.el === el)) { + if (this.ListenerQueue.some((item) => item.el === el)) { this.update(el, binding); return nextTick(this.lazyLoadHandler); } diff --git a/packages/vant-lazyload/src/listener.js b/packages/vant-lazyload/src/listener.js index bd41ced8b..6a7fdb4c9 100644 --- a/packages/vant-lazyload/src/listener.js +++ b/packages/vant-lazyload/src/listener.js @@ -1,12 +1,5 @@ import { loadImageAsync, noop } from './util'; -// el: { -// state, -// src, -// error, -// loading -// } - export default class ReactiveListener { constructor({ el, diff --git a/packages/vant-lazyload/src/util.js b/packages/vant-lazyload/src/util.js index 1fd163140..21ad75664 100644 --- a/packages/vant-lazyload/src/util.js +++ b/packages/vant-lazyload/src/util.js @@ -57,17 +57,6 @@ function remove(arr, item) { 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) { if (el.tagName !== 'IMG' || !el.getAttribute('data-srcset')) return; @@ -290,15 +279,6 @@ function isObject(obj) { 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() {} class ImageCache { @@ -331,10 +311,8 @@ export { inBrowser, CustomEvent, remove, - some, find, noop, - ArrayFrom, _, isObject, throttle,