Skip to content

Commit 82ad71e

Browse files
committed
Fix T&G issues with updating state rapidly
1 parent d71a8b4 commit 82ad71e

3 files changed

Lines changed: 292 additions & 23 deletions

File tree

lib/js/src/manager/screen/_TextAndGraphicManagerBase.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*/
3232

3333
import { _SubManagerBase } from '../_SubManagerBase.js';
34-
import { _Task } from '../_Task.js';
3534
import { _TextAndGraphicUpdateOperation } from './_TextAndGraphicUpdateOperation.js';
3635
import { _TextAndGraphicState } from './_TextAndGraphicState.js';
3736

@@ -139,17 +138,6 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
139138
* @param {function} listener - A function to invoke when the update task is complete once it runs
140139
*/
141140
_sdlUpdate (supersedePreviousOperations, listener) {
142-
if (this._updateOperation !== null && this._updateOperation.getState() === _Task.READY && supersedePreviousOperations) {
143-
this._updateOperation.switchStates(_Task.CANCELED);
144-
if (typeof this._currentOperationListener === 'function') {
145-
this._currentOperationListener(false);
146-
}
147-
}
148-
149-
if (this._updateOperation !== null && this._updateOperation.getState() === _Task.IN_PROGRESS && supersedePreviousOperations) {
150-
this._updateOperation.switchStates(_Task.CANCELED);
151-
}
152-
153141
this._currentOperationListener = listener;
154142

155143
const currentScreenDataUpdateListener = (asyncListener) => {
@@ -158,8 +146,8 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
158146
this._currentScreenData = newScreenData;
159147
this._updatePendingOperationsWithNewScreenData();
160148
}
161-
}).catch((err) => {
162-
this._resetFieldsToCurrentScreenData();
149+
}).catch((errorState) => {
150+
this._updatePendingOperationsWithFailedScreenState(errorState);
163151
});
164152
};
165153

@@ -189,11 +177,27 @@ class _TextAndGraphicManagerBase extends _SubManagerBase {
189177
this._templateConfiguration = this._currentScreenData.getTemplateConfiguration();
190178
}
191179

180+
/**
181+
* Updates all pending tasks in the queue with the failed screen state
182+
* @param {_TextAndGraphicState} errorState - The _TextAndGraphicState when the error occured
183+
* @private
184+
*/
185+
_updatePendingOperationsWithFailedScreenState (errorState) {
186+
for (const task of this._getTasks()) {
187+
if (!(task instanceof _TextAndGraphicUpdateOperation)) {
188+
continue;
189+
}
190+
if (errorState instanceof _TextAndGraphicState) { // check if a _TextAndGraphicState was passed in instead of an error object
191+
task._updateTargetStateWithErrorState(errorState);
192+
}
193+
}
194+
}
195+
192196
/**
193197
* Updates all pending tasks in the queue with the current screen data
194198
*/
195199
_updatePendingOperationsWithNewScreenData () {
196-
for (const task in this._getTasks()) {
200+
for (const task of this._getTasks()) {
197201
if (!(task instanceof _TextAndGraphicUpdateOperation)) {
198202
continue;
199203
}

lib/js/src/manager/screen/_TextAndGraphicUpdateOperation.js

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class _TextAndGraphicUpdateOperation extends _Task {
8787
this._fullShow = this._assembleLayout(this._fullShow);
8888

8989
if (this._showRpcSupportsTemplateConfiguration()) {
90-
this._updateGraphicsAndShow(this._fullShow);
90+
await this._updateGraphicsAndShow(this._fullShow);
9191
} else {
9292
if (this._shouldUpdateTemplateConfig()) {
9393
const success = await this._sendSetDisplayLayoutWithTemplateConfiguration(this._updatedState.getTemplateConfiguration());
@@ -96,9 +96,9 @@ class _TextAndGraphicUpdateOperation extends _Task {
9696
this._finishOperation(false);
9797
return;
9898
}
99-
this._updateGraphicsAndShow(this._fullShow);
99+
await this._updateGraphicsAndShow(this._fullShow);
100100
} else {
101-
this._updateGraphicsAndShow(this._fullShow);
101+
await this._updateGraphicsAndShow(this._fullShow);
102102
}
103103
}
104104
}
@@ -146,7 +146,7 @@ class _TextAndGraphicUpdateOperation extends _Task {
146146
} else {
147147
console.info('Text and Graphic Show failed');
148148
this._currentScreenDataUpdateListener(async () => {
149-
throw new Error('Text and Graphic Show failed');
149+
throw this._updatedState; // send the errored state back to the manager
150150
});
151151
}
152152
return response.getSuccess();
@@ -860,6 +860,59 @@ class _TextAndGraphicUpdateOperation extends _Task {
860860
}
861861
this.onFinished();
862862
}
863+
864+
/**
865+
* Applies changes to the _TextAndGraphicState with that of the error state
866+
* @private
867+
* @param {_TextAndGraphicState} errorState - The _TextAndGraphicState when the error occured
868+
*/
869+
_updateTargetStateWithErrorState (errorState) {
870+
if (errorState.getTextField1() === this._updatedState.getTextField1()) {
871+
this._updatedState.setTextField1(this._currentScreenData.getTextField1());
872+
}
873+
if (errorState.getTextField2() === this._updatedState.getTextField2()) {
874+
this._updatedState.setTextField2(this._currentScreenData.getTextField2());
875+
}
876+
if (errorState.getTextField3() === this._updatedState.getTextField3()) {
877+
this._updatedState.setTextField3(this._currentScreenData.getTextField3());
878+
}
879+
if (errorState.getTextField4() === this._updatedState.getTextField4()) {
880+
this._updatedState.setTextField4(this._currentScreenData.getTextField4());
881+
}
882+
if (errorState.getMediaTrackTextField() === this._updatedState.getMediaTrackTextField()) {
883+
this._updatedState.setMediaTrackTextField(this._currentScreenData.getMediaTrackTextField());
884+
}
885+
if (errorState.getTitle() === this._updatedState.getTitle()) {
886+
this._updatedState.setTitle(this._currentScreenData.getTitle());
887+
}
888+
if ((errorState.getPrimaryGraphic() === null && this._updatedState.getPrimaryGraphic() === null)
889+
|| (errorState.getPrimaryGraphic() !== null && errorState.getPrimaryGraphic().equals(this._updatedState.getPrimaryGraphic()))) { // for safe null check
890+
this._updatedState.setPrimaryGraphic(this._currentScreenData.getPrimaryGraphic());
891+
}
892+
if ((errorState.getSecondaryGraphic() === null && this._updatedState.getSecondaryGraphic() === null)
893+
|| (errorState.getSecondaryGraphic() !== null && errorState.getSecondaryGraphic().equals(this._updatedState.getSecondaryGraphic()))) { // for safe null check
894+
this._updatedState.setSecondaryGraphic(this._currentScreenData.getSecondaryGraphic());
895+
}
896+
if (errorState.getTextAlignment() === this._updatedState.getTextAlignment()) {
897+
this._updatedState.setTextAlignment(this._currentScreenData.getTextAlignment());
898+
}
899+
if (errorState.getTextField1Type() === this._updatedState.getTextField1Type()) {
900+
this._updatedState.setTextField1Type(this._currentScreenData.getTextField1Type());
901+
}
902+
if (errorState.getTextField2Type() === this._updatedState.getTextField2Type()) {
903+
this._updatedState.setTextField2Type(this._currentScreenData.getTextField2Type());
904+
}
905+
if (errorState.getTextField3Type() === this._updatedState.getTextField3Type()) {
906+
this._updatedState.setTextField3Type(this._currentScreenData.getTextField3Type());
907+
}
908+
if (errorState.getTextField4Type() === this._updatedState.getTextField4Type()) {
909+
this._updatedState.setTextField4Type(this._currentScreenData.getTextField4Type());
910+
}
911+
if ((errorState.getTemplateConfiguration() === null && this._updatedState.getTemplateConfiguration() === null)
912+
|| (errorState.getTemplateConfiguration() !== null && errorState.getTemplateConfiguration().getParameters() === this._updatedState.getTemplateConfiguration().getParameters())) { // for safe null check
913+
this._updatedState.setTemplateConfiguration(this._currentScreenData.getTemplateConfiguration());
914+
}
915+
}
863916
}
864917

865918
export { _TextAndGraphicUpdateOperation };

0 commit comments

Comments
 (0)