Skip to content

Unsubscribing from a non-existent channel has unintended outcome

From the following setup:

const spyObj = {};
const pubSubInstance =  pubSub(spyObj);
const topicA = 'testA';
const topicB = 'testB';
const topicDud = 'NoSubscribers';
const noop = () => {};
// excercise
pubSubInstance.subscribe(topicA, noop);
pubSubInstance.subscribe(topicB, noop);
// - take clone of spyObj for comparison after dud unsub
const spyObjClone = Object.assign({},spyObj);
pubSubInstance.unsubscribe(topicDud, noop);

console.log('spyObjClone', spyObjClone);
console.log('spyObj', spyObj);

The following is observered:

spyObjClone { 
  testA: [ [Function: noop] ], 
  testB: [ [Function: noop] ] 
}
spyObj {
  testA: [ [Function: noop] ],
  testB: [ [Function: noop] ],
  NoSubscribers: undefined
}

The value 'NoSubscribers' should not be a topic in the channel.

Edited by Jon Lee-White