Skip to content

Commit ac9cc5a

Browse files
author
jinwoo-choi-05
committed
chore: add type info
1 parent 5a2804a commit ac9cc5a

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/core/AutoResizer.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class AutoResizer {
3535
const viewportSizeNot0 = viewport.width !== 0 || viewport.height !== 0;
3636

3737
const resizeObserver = viewportSizeNot0
38-
? new ResizeObserver((entries) => this._skipFirstResize(entries))
39-
: new ResizeObserver((entries) => this._onResize(entries));
38+
? new ResizeObserver((entries: ResizeObserverEntry[]) => this._skipFirstResize(entries))
39+
: new ResizeObserver((entries: ResizeObserverEntry[]) => this._onResize(entries));
4040

4141
resizeObserver.observe(flicking.viewport.element);
4242

4343
this._resizeObserver = resizeObserver;
4444
} else {
45-
window.addEventListener("resize", this._onResize);
45+
window.addEventListener("resize", () => this._onResize([]));
4646
}
4747

4848
this._enabled = true;
@@ -58,37 +58,38 @@ class AutoResizer {
5858
resizeObserver.disconnect();
5959
this._resizeObserver = null;
6060
} else {
61-
window.removeEventListener("resize", this._onResize);
61+
window.removeEventListener("resize", () => this._onResize([]));
6262
}
6363

6464
this._enabled = false;
6565

6666
return this;
6767
}
6868

69-
private _onResize = (entries: any) => {
69+
private _onResize = (entries: ResizeObserverEntry[]) => {
7070
const flicking = this._flicking;
7171
const resizeDebounce = flicking.resizeDebounce;
7272
const maxResizeDebounce = flicking.maxResizeDebounce;
7373

74-
const resizeEntryInfo = entries[0].contentRect;
75-
76-
const beforeSize = {
77-
width: flicking.viewport.width,
78-
height: flicking.viewport.height
79-
};
80-
81-
const afterSize = {
82-
width: resizeEntryInfo.width,
83-
height: resizeEntryInfo.height
84-
};
85-
86-
// resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
87-
if (
88-
beforeSize.height === afterSize.height &&
89-
beforeSize.width === afterSize.width
90-
) {
91-
return;
74+
if (entries.length) {
75+
const resizeEntryInfo = entries[0].contentRect;
76+
const beforeSize = {
77+
width: flicking.viewport.width,
78+
height: flicking.viewport.height
79+
};
80+
81+
const afterSize = {
82+
width: resizeEntryInfo.width,
83+
height: resizeEntryInfo.height
84+
};
85+
86+
// resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
87+
if (
88+
beforeSize.height === afterSize.height &&
89+
beforeSize.width === afterSize.width
90+
) {
91+
return;
92+
}
9293
}
9394

9495
if (resizeDebounce <= 0) {

0 commit comments

Comments
 (0)