Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions src/utils/real_time_updates/withRealTimeUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ const withRealTimeUpdates = WrappedComponent => {
* @returns {Promise<void>}
*/
async processUpdates(updates) {

const {summit, allEvents, allIDXEvents, allSpeakers, allIDXSpeakers, synchEntityData} = this.props;

if(!this._worker)
{
console.log('withRealTimeUpdates::processUpdates worker is null');
const worker = this._worker;
if (!worker) {
console.log('withRealTimeUpdates::processUpdates worker is null (early return)');
return;
}

Expand All @@ -87,9 +86,15 @@ const withRealTimeUpdates = WrappedComponent => {
accessToken = await getAccessToken();
} catch (e) {
console.log('withRealTimeUpdates::processUpdates getAccessToken error: ', e);
return;
}

this._worker.postMessage({
if (worker !== this._worker) {
console.log('withRealTimeUpdates::processUpdates worker changed or was destroyed (post-await)');
return;
}

worker.postMessage({
accessToken: accessToken,
noveltiesArray: JSON.stringify(updates),
summit: JSON.stringify(summit),
Expand All @@ -100,31 +105,28 @@ const withRealTimeUpdates = WrappedComponent => {
currentLocation: this.getCurrentLocation()
});

this._worker.onmessage = ({
data: {
payload,
entity,
summit,
eventsData,
allIDXEvents: newAllIDXEvents,
allSpeakers: newAllSpeakers,
allIDXSpeakers: newAllIDXSpeakers
}
}) => {

worker.onmessage = ({
data: {
payload,
entity,
summit,
eventsData,
allIDXEvents: newAllIDXEvents,
allSpeakers: newAllSpeakers,
allIDXSpeakers: newAllIDXSpeakers
}
}) => {
console.log('withRealTimeUpdates::processUpdates calling synch worker on message ');

synchEntityData
(
synchEntityData(
payload,
entity,
summit,
eventsData,
newAllIDXEvents,
newAllSpeakers,
newAllIDXSpeakers
)
}
);
};
}

/**
Expand Down