Skip to content

Commit

Permalink
Cleanup after review
Browse files Browse the repository at this point in the history
- Get rid of optional chaining as we know the variable will be non-null
  • Loading branch information
mofojed committed Mar 12, 2024
1 parent 18ed118 commit 2e6be04
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plugins/ui/src/js/src/widget/WidgetHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@ function WidgetHandler({
const widgetExportedObjectMap = new Map<number, WidgetExportedObject>();
exportedObjectMap.current = widgetExportedObjectMap;
exportedObjectCount.current = 0;

// Set a var to the client that we know will not be null in the closure below
const activeClient = jsonClient;
function receiveData(
data: string,
newExportedObjects: WidgetExportedObject[]
) {
log.debug2('Data received', data, newExportedObjects);
updateExportedObjects(newExportedObjects);
if (data.length > 0) {
jsonClient?.receiveAndSend(JSON.parse(data));
activeClient.receiveAndSend(JSON.parse(data));
}
}

Expand All @@ -243,7 +246,7 @@ function WidgetHandler({
receiveData(widget.getDataAsString(), widget.exportedObjects);

// We set the initial state of the widget. We'll then get a documentUpdated as a response.
jsonClient?.request('setState', [initialData?.state ?? {}]).then(
activeClient.request('setState', [initialData?.state ?? {}]).then(
result => {
log.debug('Set state result', result);
},
Expand Down

0 comments on commit 2e6be04

Please sign in to comment.