Skip to content

Commit

Permalink
Merge pull request #188 from MasatoMakino/change-#86
Browse files Browse the repository at this point in the history
chage : rename to "restart"
  • Loading branch information
MasatoMakino committed May 27, 2024
2 parents f024f17 + a8a33b8 commit 880059b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions __test__/sleep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("threejs-drag-watcher", () => {
clearMockFunctions();
});

test("reset timer", () => {
test("restart timer", () => {
sleepWatcher.start();

interval(timeout_ms * 0.6);
Expand All @@ -170,7 +170,7 @@ describe("threejs-drag-watcher", () => {

dispatchMouseEvent("pointerdown", { offsetX: 0, offsetY: 0 });
interval(timeout_ms * 0.6);
sleepWatcher.reset();
sleepWatcher.restart();
interval(timeout_ms * 0.6);
expect(mockSleep).not.toBeCalled();
clearMockFunctions();
Expand Down
21 changes: 10 additions & 11 deletions src/SleepWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ export class SleepWatcher extends EventEmitter<SleepEventMap> {

/**
* 無操作タイマーをリセットし、再度カウントを開始する。
* @deprecated This method will be removed in v0.13.0. Please use restart() instead.
*/
public reset(): void {
this.stopTimer();
this.wakeup();

this.sleepTimerID = window.setTimeout(this.sleep, this.timeOut_ms);
this.restart();
}

/**
* 無操作タイマーをリセットし、再度カウントを開始する。
* zoomイベントハンドラー
*/
private resetTimer = () => {
this.reset();
public restart = (): void => {
this.stopTimer();
this.wakeup();
this.sleepTimerID = window.setTimeout(this.sleep, this.timeOut_ms);
};

private stopTimer(): void {
Expand All @@ -57,12 +56,12 @@ export class SleepWatcher extends EventEmitter<SleepEventMap> {
public start(): void {
this.stopMouseEventListeners();
this.startMouseEventListeners();
this.resetTimer();
this.restart();
}

protected startMouseEventListeners(): void {
const watcher = this.dragWatcher;
watcher.on("zoom", this.resetTimer);
watcher.on("zoom", this.restart);
watcher.on("drag_start", this.pauseTimer);
}

Expand All @@ -76,7 +75,7 @@ export class SleepWatcher extends EventEmitter<SleepEventMap> {
};

private resumeTimer = () => {
this.resetTimer();
this.restart();

const watcher = this.dragWatcher;
watcher.on("drag_start", this.pauseTimer);
Expand All @@ -94,7 +93,7 @@ export class SleepWatcher extends EventEmitter<SleepEventMap> {

protected stopMouseEventListeners(): void {
const watcher = this.dragWatcher;
watcher.off("zoom", this.resetTimer);
watcher.off("zoom", this.restart);
watcher.off("drag_start", this.pauseTimer);
watcher.off("drag_end", this.resumeTimer);
}
Expand Down

0 comments on commit 880059b

Please sign in to comment.