Skip to content

Commit

Permalink
Re-fix #12095 again (#12138)
Browse files Browse the repository at this point in the history
Unfortunately some of the suggested changes to #12095 introduced
bugs which due to caching behaviour of sharedworkers were not caught
on simple tests.

These are as follows:

* Changing from simple for loop to use includes here:

```js
  register(port) {
    if (!this.clients.includes(port)) return;

    this.clients.push(port);

    port.postMessage({
      type: 'status',
      message: `registered to ${this.url}`,
    });
  }
```

The additional `!` prevents any clients from being added and should
read:

```js
    if (this.clients.includes(port)) return;
```

* Dropping the use of jQuery `$(...)` selection and using DOM
`querySelector` here:

```js
async function receiveUpdateCount(event) {
  try {
    const data = JSON.parse(event.data);

    const notificationCount = document.querySelector('.notification_count');
    if (data.Count > 0) {
      notificationCount.classList.remove('hidden');
    } else {
      notificationCount.classList.add('hidden');
    }

    notificationCount.text() = `${data.Count}`;
    await updateNotificationTable();
  } catch (error) {
    console.error(error, event);
  }
}
```

Requires that `notificationCount.text()` be changed to use `textContent`
instead.

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored Jul 4, 2020
1 parent 60cb9fe commit 3c4388f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web_src/js/features/eventsource.sharedworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Source {
}

register(port) {
if (!this.clients.includes(port)) return;
if (this.clients.includes(port)) return;

this.clients.push(port);

Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function receiveUpdateCount(event) {
notificationCount.classList.add('hidden');
}

notificationCount.text(`${data.Count}`);
notificationCount.textContent = `${data.Count}`;
await updateNotificationTable();
} catch (error) {
console.error(error, event);
Expand Down

0 comments on commit 3c4388f

Please sign in to comment.