-
Couldn't load subscription status.
- Fork 1
Troubleshooting
Eric M. Dantas edited this page Aug 19, 2016
·
1 revision
There are a few things that could be happening, here are some of the most common:
- You're calling
bus.emit('ev')before calledbus.on('ev', () => {}), so there's nobody listening what you just sent:
let bus = new Bus();
bus.emit('yo', {hey: '!'});
bus.on('yo', (info) => {
console.log(info); // not going to be called, the info has already been sent
});- You're using different instances of the Bus. Say you do the following:
let bus1 = new Bus();
let bus2 = new Bus();
bus1.on('yo', (info) => {
console.log(info);
});
bus2.emit('yo', {hey: '!'});The above example will never trigger the listener, because bus1 and bus2 are different instances of Bus, to fix that, use the same instance:
let bus1 = new Bus();
bus1.on('yo', (info) => {
console.log(info); // {hey: '!'};
});
bus1.emit('yo', {hey: '!'});- You have different tokens for the publisher and listeners - they have to be equal as in
tokenListener === tokenPublisher:
let bus = new Bus();
// notice the space in the end, it should be 'ev', not 'ev '
bus.on('ev ', (info) => {
console.log(info);
});
bus.emit('ev', '!');