Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: destroy after resize #860

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Flicking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,9 @@ class Flicking extends Component<FlickingEvents> {

viewport.resize();
await renderer.forceRenderAllPanels(); // Render all panel elements, to update sizes
if (!this._initialized) {
return;
}
renderer.updatePanelSize();
camera.updateAlignPos();
camera.updateRange();
Expand All @@ -1511,6 +1514,9 @@ class Flicking extends Component<FlickingEvents> {
camera.updatePanelOrder();
camera.updateOffset();
await renderer.render();
if (!this._initialized) {
return;
}

if (control.animating) {
// TODO:
Expand Down
17 changes: 16 additions & 1 deletion test/unit/Flicking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Plugin } from "~/type/external";
import { AfterResizeEvent, BeforeResizeEvent } from "~/type/event";

import El from "./helper/El";
import { cleanup, createFlicking, range, simulate, tick, waitEvent } from "./helper/test-util";
import { cleanup, createFlicking, range, simulate, tick, waitEvent, waitTime } from "./helper/test-util";

describe("Flicking", () => {
afterEach(() => {
Expand Down Expand Up @@ -1832,6 +1832,21 @@ describe("Flicking", () => {
expect(cameraSpy.calledOnce).to.be.true;
expect(rendererSpy.calledOnce).to.be.true;
});
it("should call destroy after resize", async () => {
const flicking = await createFlicking(El.DEFAULT_HORIZONTAL);

let hasError = false;
flicking.resize().catch(() => {
// Any remaining resize operations that occur after destroy should not operate.
hasError = true;
});
flicking.destroy();

await waitTime(1000);

// Then
expect(hasError).to.be.equal(false);
});
});

describe("getElement()", () => {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/helper/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@ export const waitEvent = (emitter: any, eventName: string) => {
}
};


export const waitTime = (time: number) => {
return new Promise(res => {
(window as any)._real.setTimeout(res, time);
});
}

export class NullClass {}
4 changes: 4 additions & 0 deletions test/unit/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
(window as any)._real = {
setTimeout: (window as any).setTimeout.bind((window as any)),
};

(window as any).timer = sinon.useFakeTimers();
(window as any).flickings = [];

Expand Down
Loading