Skip to content

Commit

Permalink
fix(ui/lazy): 增加绑定事件配置
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Dec 24, 2020
1 parent a327258 commit 64a95cb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/varlet-ui/src/lazy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface LazyOptions {
attempt?: number
throttleWait?: number
filter?: (lazy: Lazy) => void
events?: string[]
}

type Lazy = LazyOptions & {
Expand Down Expand Up @@ -46,6 +47,7 @@ let defaultLazyOptions: LazyOptions = {
error: PIXEL,
attempt: 3,
throttleWait: 300,
events: EVENTS
}

let checkAllWithThrottle = throttle(checkAll, defaultLazyOptions.throttleWait)
Expand Down Expand Up @@ -92,14 +94,14 @@ function bindEvents(listenTarget: ListenTarget) {
}
listenTargets.push(listenTarget)

EVENTS.forEach((event: string) => {
defaultLazyOptions.events.forEach((event: string) => {
listenTarget.addEventListener(event, checkAllWithThrottle)
})
}

function unbindEvents() {
listenTargets.forEach((listenTarget: ListenTarget) => {
EVENTS.forEach((event: string) => {
defaultLazyOptions.events.forEach((event: string) => {
listenTarget.removeEventListener(event, checkAllWithThrottle)
})
})
Expand Down Expand Up @@ -221,10 +223,8 @@ function mounted(el: LazyHTMLElement, binding: DirectiveBinding<string>) {
if (useIntersectionObserverAPI) {
observe(el)
} else {
if (!lazyElements.includes(el) && lazyElements.push(el) === 1) {
bindEvents(window)
bindEvents(getParentScroller(el))
}
bindEvents(window)
bindEvents(getParentScroller(el))
check(el)
}
}
Expand Down

0 comments on commit 64a95cb

Please sign in to comment.