Skip to content

Commit db78411

Browse files
committed
simpler
1 parent 29cb7ec commit db78411

File tree

1 file changed

+7
-16
lines changed
  • services/static-webserver/client/source/class/osparc/desktop

1 file changed

+7
-16
lines changed

services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
8181
});
8282

8383
this.__updatingStudy = 0;
84-
this.__lastPatchTime = 0;
85-
this.__throttledPendingUpdate = false;
84+
this.__throttledPatchPending = false;
8685
},
8786

8887
events: {
@@ -124,8 +123,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
124123
__updatingStudy: null,
125124
__updateThrottled: null,
126125
__nodesSlidesTree: null,
127-
__lastPatchTime: null,
128-
__throttledPendingUpdate: null,
126+
__throttledPatchPending: null,
129127

130128
setStudyData: function(studyData) {
131129
if (this.__settingStudy) {
@@ -919,20 +917,13 @@ qx.Class.define("osparc.desktop.StudyEditor", {
919917

920918
this.getStudy().setSavePending(true);
921919
// throttling: do not update study document right after a change, wait for THROTTLE_PATCH_TIME
922-
const throttlePatchTime = this.self().THROTTLE_PATCH_TIME;
923-
const now = Date.now();
924-
const timeSinceLastUpdate = now - this.__lastPatchTime;
925-
if (timeSinceLastUpdate >= throttlePatchTime) {
926-
this.updateStudyDocument();
927-
this.__lastPatchTime = now;
928-
} else if (!this.__throttledPendingUpdate) {
929-
// Otherwise, schedule a call after remaining time
930-
this.__throttledPendingUpdate = true;
920+
if (!this.__throttledPatchPending) {
921+
this.__throttledPatchPending = true;
922+
931923
setTimeout(() => {
932924
this.updateStudyDocument();
933-
this.__lastPatchTime = Date.now();
934-
this.__throttledPendingUpdate = false;
935-
}, throttlePatchTime - timeSinceLastUpdate);
925+
this.__throttledPatchPending = false;
926+
}, this.self().THROTTLE_PATCH_TIME);
936927
}
937928
},
938929

0 commit comments

Comments
 (0)