Skip to content

Commit dae09b6

Browse files
committed
refactor: 🏷️ add types
1 parent 8b99dcf commit dae09b6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/lib/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const getPadding = aspectRatio => {
1+
export const getPadding = (aspectRatio: string) => {
22
const config = {
33
'1:1': `padding-top: 100%;`,
44
'16:9': `padding-top: 56.25%;`,

src/lib/utils/use-viewport-action.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
// Thanks Lihau https://www.youtube.com/watch?v=1SKKzdHVvcI&t=182s
22

3-
let intersectionObserver
3+
let intersectionObserver: IntersectionObserver
44

55
function ensureIntersectionObserver() {
66
if (intersectionObserver) return
77

8-
intersectionObserver = new IntersectionObserver(entries => {
9-
entries.filter(({isIntersecting}) => isIntersecting).forEach(entry => {
10-
entry.target.dispatchEvent(new CustomEvent('enterViewport'))
11-
})
12-
}, {
13-
rootMargin: "1000px"
14-
})
8+
intersectionObserver = new IntersectionObserver(
9+
entries => {
10+
entries
11+
.filter(({ isIntersecting }) => isIntersecting)
12+
.forEach(entry => {
13+
entry.target.dispatchEvent(new CustomEvent('enterViewport'))
14+
})
15+
},
16+
{
17+
rootMargin: '1000px',
18+
}
19+
)
1520
}
1621

17-
export default function viewport(element) {
22+
export default function viewport(element: Element) {
1823
ensureIntersectionObserver()
1924

2025
intersectionObserver.observe(element)

0 commit comments

Comments
 (0)