Skip to content

Commit

Permalink
feat(js): introduce SwipeDetector class to manage multiple detectors
Browse files Browse the repository at this point in the history
Added the SwipeDetector class in swiperia-js to orchestrate multiple swipe detection mechanisms simultaneously. This class allows for the initialization of various detector instances (such as MouseSwipeDetector and TouchSwipeDetector) and manages their lifecycle through common `listen` and `destroy` methods. This setup enables seamless integration and management of different swipe detection strategies within the same element.
  • Loading branch information
samavati committed Apr 13, 2024
1 parent c06c780 commit db80471
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/swiperia-js/src/lib/SwipeDetector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { SwipeCallback, SwipeConfig } from 'swiperia-core';
import { AbstractSwipeDetector } from './AbstractSwipeDetector';

export class SwipeDetector {
private _detectors: AbstractSwipeDetector[] = [];
constructor(
public el: HTMLElement,
public detectors: (new (
el: HTMLElement,
config?: SwipeConfig
) => AbstractSwipeDetector)[],
public config?: SwipeConfig
) {}

listen(callback: SwipeCallback) {
for (let Detector of this.detectors) {
const instance = new Detector(this.el, this.config);
this._detectors.push(instance);
instance.listen(callback);
}
}

destroy() {
for (let detector of this._detectors) {
detector.destroy();
}
}
}

0 comments on commit db80471

Please sign in to comment.