Skip to content

Commit

Permalink
Fix: dispatchEvent now emits entire event object
Browse files Browse the repository at this point in the history
It now emits the entire `Event` object and not only `CustomEvent.detail`.
  • Loading branch information
Akwd22 committed Aug 17, 2022
1 parent 1b66b92 commit eb430c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,8 @@ EventSource.prototype.dispatchEvent = function dispatchEvent (event) {
if (!event.type) {
throw new Error('UNSPECIFIED_EVENT_TYPE_ERR')
}
// if event is instance of an CustomEvent (or has 'details' property),
// send the detail object as the payload for the event
this.emit(event.type, event.detail)

this.emit(event.type, event)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/eventsource_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ describe('Events', function () {
server.close(done)
})

es.dispatchEvent({type: 'greeting', detail: {data: 'Hello'}})
es.dispatchEvent({type: 'greeting', data: 'Hello'})
})
})
})
Expand Down

0 comments on commit eb430c0

Please sign in to comment.