Skip to content

Commit

Permalink
fix: Updated logic to return error on failing to listen the events (#65)
Browse files Browse the repository at this point in the history
* Updated logic to return error on failing to listen the events

* Updated logic to return error on failing to listen the events

* Reverted format
  • Loading branch information
kevinshahfws authored Nov 4, 2022
1 parent 570866a commit 846709e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/js/shared/Events/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,21 @@ const doListen = function(module, event, callback, context, once, internal=false

events.forEach(event => {
const key = module + '.' + event + (hasContext ? `.${contextKey}` : '')

if (Object.values(listeners.get(key)).length === 0) {
const { id, promise } = Transport.listen(module, 'on' + event[0].toUpperCase() + event.substring(1), { listen: true })
keys[id] = key
promises.push(promise)
}

const setter = internal ? listeners.setInternal : listeners.set

if (wildcard) {
setter(key, ''+listenerId, value => callback(event, value))
}
else {
setter(key, ''+listenerId, callback)
const setter = internal ? listeners.setInternal : listeners.set
promise.then( id => {
if (wildcard) {
setter(key, ''+listenerId, value => callback(event, value))
}
else {
setter(key, ''+listenerId, callback)
}
}).catch( error => {
reject(error)
})
}
})

Expand All @@ -183,7 +184,7 @@ const doListen = function(module, event, callback, context, once, internal=false
else {
resolve(listenerId)
}

return p
}
}
Expand Down

0 comments on commit 846709e

Please sign in to comment.