diff --git a/src/EventSource.js b/src/EventSource.js index 6a7b146..cc73d2c 100644 --- a/src/EventSource.js +++ b/src/EventSource.js @@ -6,6 +6,8 @@ const XMLReadyStateMap = [ 'DONE', ]; +const allowedMethods = ['onopen', 'onmessage', 'onerror']; + class EventSource { ERROR = -1; CONNECTING = 0; @@ -294,6 +296,12 @@ class EventSource { dispatch(type, data) { const availableTypes = Object.keys(this.eventHandlers); + const key = `on${type}`; + const callback = this[key]; + if(typeof callback === 'function' && allowedMethods.includes(key)) { + callback(data); + } + if (!availableTypes.includes(type)) { return; }