Skip to content

Commit

Permalink
Merge pull request #207 from zendesk/wxing/clear-request-handlers
Browse files Browse the repository at this point in the history
Clear handlers of request:X.done and request:X.fail of the request
  • Loading branch information
yaraya24 authored Jun 19, 2023
2 parents ae7cdab + 1f782af commit a059fe1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,23 @@ export default class Client {
options = { url: options }
}

this.on(requestKey + '.done', (evt) => {
const doneEventKey = `${requestKey}.done`
const failEventKey = `${requestKey}.fail`

const doneHandler = (evt) => {
resolve.apply(this, evt.responseArgs)
})
this.off(failEventKey, failHandler)
this.off(doneEventKey, doneHandler)
}

this.on(requestKey + '.fail', (evt) => {
const failHandler = (evt) => {
reject.apply(this, evt.responseArgs)
})
this.off(failEventKey, failHandler)
this.off(doneEventKey, doneHandler)
}

this.on(doneEventKey, doneHandler)
this.on(failEventKey, failHandler)

this.postMessage(requestKey, options)
})
Expand Down

0 comments on commit a059fe1

Please sign in to comment.