returned undefined if we don't have the event

This commit is contained in:
FrankRua 2022-01-17 17:04:40 -05:00
parent b8d5f7a72d
commit 3ab5a97a4c

View file

@ -15,6 +15,7 @@ export default {
readAndPopEventFromBus(category, subCategory) {
// Match our item and find the index
const matchedEvent = store.state.applicationUser.eventBus.find(({ category, subCategory }) => category === category && subCategory === subCategory);
const itemIndex = store.state.applicationUser.eventBus.indexOf(matchedEvent);
// If the item exists, remove it.
@ -22,13 +23,14 @@ export default {
store.state.applicationUser.eventBus.splice(itemIndex, 1);
}
return matchedEvent.eventValue;
return matchedEvent === undefined ? undefined : matchedEvent.eventValue;
},
// Finds the event on the bus and returns its value to the caller, does not remove it.
readEventFromBus(category, subCategory) {
const matchedEvent = store.state.applicationUser.eventBus.find(({ category, subCategory }) => category === category && subCategory === subCategory);
return matchedEvent.eventValue;
return matchedEvent === undefined ? undefined : matchedEvent.eventValue;
},
// Checks if an item is on the bus or not, useful when you don't care about the value.