Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Commit

Permalink
Remove the fragment of subscription URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Mar 7, 2019
1 parent d72b162 commit d116fb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/UpdateTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export default class UpdateTracker {

/** Subscribes to changes in the given resources */
subscribe(...urls) {
for (const url of urls) {
for (let url of urls) {
// Create a new subscription if none exists for the resource
url = url.replace(/#.*/, '');
if (!(url in subscribers)) {
const webSocket = this.getWebSocketFor(url);
webSocket.enqueue(`sub ${url}`);
Expand All @@ -29,7 +30,8 @@ export default class UpdateTracker {

/** Unsubscribes to changes in the given resources */
unsubscribe(...urls) {
for (const url of urls) {
for (let url of urls) {
url = url.replace(/#.*/, '');
if (url in subscribers)
subscribers[url].delete(this.subscriber);
}
Expand Down
6 changes: 5 additions & 1 deletion test/UpdateTracker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('An UpdateTracker', () => {
'http://a.com/docs/1',
'http://a.com/docs/2',
'http://b.com/docs/3',
'http://b.com/docs/3#thing',
];
let webSockets;
beforeAll(() => {
Expand Down Expand Up @@ -127,7 +128,10 @@ describe('An UpdateTracker', () => {
describe('after unsubscribing from a resource', () => {
beforeAll(() => {
callback.mockClear();
updateTracker.unsubscribe('http://a.com/docs/1', 'http://a.com/other');
updateTracker.unsubscribe(
'http://a.com/docs/1#235',
'http://a.com/other',
);
});

it('does not call the callback when the resource changes', () => {
Expand Down

0 comments on commit d116fb5

Please sign in to comment.