Skip to content

Commit

Permalink
added lazyload handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoloza committed Jan 18, 2025
1 parent c1a44f6 commit 8970f3f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/element/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export const createNode = async (element, options) => {
}

if ((element.props && element.props.lazyLoad) || options.lazyLoad) {
window.requestAnimationFrame(async () => await createAsync())
window.requestAnimationFrame(async () => {
await createAsync()
// handle lazy load
if (!options.preventUpdateListener) {
triggerEventOn('lazyLoad', element, options)
}
})
} else await createAsync()
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/element/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ export const set = function (params, options = {}, el) {
}

if (lazyLoad) {
window.requestAnimationFrame(() => resetElement(params, element, options))
window.requestAnimationFrame(() => {
resetElement(params, element, options)
// handle lazy load
if (!options.preventUpdateListener) {
triggerEventOn('lazyLoad', element, options)
}
})
} else resetElement(params, element, options)
}

Expand Down
8 changes: 7 additions & 1 deletion packages/element/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ export const update = function (params = {}, opts) {
calleeElement
})

lazyLoad ? window.requestAnimationFrame(() => childUpdateCall()) : childUpdateCall()
lazyLoad ? window.requestAnimationFrame(() => { // eslint-disable-line
childUpdateCall()
// handle lazy load
if (!options.preventUpdateListener) {
triggerEventOn('lazyLoad', element, options)
}
}) : childUpdateCall()
}
}

Expand Down

0 comments on commit 8970f3f

Please sign in to comment.