From 898af135fa997cfdf380a285aaadd518aae141bc Mon Sep 17 00:00:00 2001 From: HF Date: Thu, 15 Sep 2022 22:46:44 +0200 Subject: [PATCH] do history updates less ofte --- src/controls/PixelPainterControls.js | 11 ++++++++--- src/server.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/controls/PixelPainterControls.js b/src/controls/PixelPainterControls.js index 6eb2b96a..c543f629 100644 --- a/src/controls/PixelPainterControls.js +++ b/src/controls/PixelPainterControls.js @@ -103,6 +103,7 @@ class PixelPlainterControls { document.activeElement.blur(); if (event.button === 0) { + clearTimeout(this.onViewFinishChangeTimeOut); this.isClicking = true; const { clientX, clientY } = event; this.clickTapStartTime = Date.now(); @@ -117,13 +118,16 @@ class PixelPlainterControls { } } + /* + * try to avoid updating history too often + */ scheduleOnViewFinishChange() { if (this.onViewFinishChangeTimeOut) { clearTimeout(this.onViewFinishChangeTimeOut); } this.onViewFinishChangeTimeOut = setTimeout(() => { this.store.dispatch(onViewFinishChange()); - }, 250); + }, 500); } onMouseUp(event) { @@ -155,7 +159,7 @@ class PixelPlainterControls { } this.viewport.style.cursor = 'auto'; } - store.dispatch(onViewFinishChange()); + this.scheduleOnViewFinishChange(); } static getTouchCenter(event) { @@ -267,6 +271,7 @@ class PixelPlainterControls { event.stopPropagation(); document.activeElement.blur(); + clearTimeout(this.onViewFinishChangeTimeOut); this.clickTapStartTime = Date.now(); this.clickTapStartCoords = PixelPlainterControls.getTouchCenter(event); const state = this.store.getState(); @@ -324,7 +329,7 @@ class PixelPlainterControls { }, 500); } } - store.dispatch(onViewFinishChange()); + this.scheduleOnViewFinishChange(); this.clearTabTimeout(); } diff --git a/src/server.js b/src/server.js index 24e81725..a8248db4 100644 --- a/src/server.js +++ b/src/server.js @@ -22,7 +22,7 @@ import SocketServer from './socket/SocketServer'; import APISocketServer from './socket/APISocketServer'; import { - PORT, HOST, HOURLY_EVENT, SHARD_NAME, + PORT, HOST, HOURLY_EVENT, } from './core/config'; import { SECOND } from './core/constants';