Skip to content

Commit

Permalink
fix: check and recover enabled status of Flicking in Sync plugin (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
malangfox authored Jan 7, 2025
1 parent 58babac commit 87671e2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface SychronizableFlickingOptions {
class Sync implements Plugin {
/* Internal Values */
private _flicking: Flicking | null = null;
private _disabledIndex: number[] = [];

/* Options */
private _type: SyncOptions["type"];
Expand Down Expand Up @@ -173,19 +174,20 @@ class Sync implements Plugin {
};

private _onMoveStart = (e: MoveStartEvent): void => {
this._synchronizedFlickingOptions.forEach(({ flicking }) => {
if (flicking !== e.currentTarget) {
this._disabledIndex = [];
this._synchronizedFlickingOptions.forEach(({ flicking }, i) => {
if (flicking !== e.currentTarget && flicking.control.controller.enabled) {
this._disabledIndex.push(i);
flicking.disableInput();
}
});
};

private _onMoveEnd = (e: MoveEndEvent): void => {

Check warning on line 186 in src/Sync.ts

View workflow job for this annotation

GitHub Actions / unit

'e' is defined but never used
this._synchronizedFlickingOptions.forEach(({ flicking }) => {
if (flicking !== e.currentTarget) {
flicking.enableInput();
flicking.control.updateInput();
}
this._disabledIndex.forEach((i) => {
const flicking = this._synchronizedFlickingOptions[i].flicking;
flicking.enableInput();
flicking.control.updateInput();
});
};

Expand Down
29 changes: 29 additions & 0 deletions test/unit/Sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,33 @@ describe("Sync", () => {
expect(flicking1.index).equal(2);
expect(flicking1.camera.position).equal(flicking1.panels[2].position);
});

[true, false].forEach((enabled) => {
it(`should check and recover enabled status of flickings (enabled: ${enabled})`, async () => {
// Given
flicking0.addPlugins(new Sync({
type: "camera",
synchronizedFlickingOptions: [
{
flicking: flicking0
},
{
flicking: flicking1
}
]
}));
await waitEvent(flicking0, "ready");

if (!enabled) {
flicking1.disableInput();
}

// When
void flicking0.control.moveToPosition(500, 0);

// Then
expect(flicking1.camera.position).equal(1100);
expect(flicking1.control.controller.enabled).equal(enabled);
});
})
});

0 comments on commit 87671e2

Please sign in to comment.