File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ export type EventSourceListener<E extends string = never> = (
57
57
) => void ;
58
58
59
59
declare class EventSource < E extends string = never > {
60
- constructor ( url : URL | string , options ?: EventSourceOptions ) ;
60
+ constructor ( url : URL | string , options ?: EventSourceOptions = { } ) ;
61
61
open ( ) : void ;
62
62
close ( ) : void ;
63
63
addEventListener ( type : E | EventType , listener : EventSourceListener < E > ) : void ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-native-sse" ,
3
- "version" : " 1.0.4 " ,
3
+ "version" : " 1.0.5 " ,
4
4
"description" : " EventSource implementation for React Native. Server-Sent Events (SSE) for iOS and Android." ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ class EventSource {
4
4
OPEN = 1 ;
5
5
CLOSED = 2 ;
6
6
7
- constructor ( url , options ) {
7
+ constructor ( url , options = { } ) {
8
8
this . interval = options . pollingInterval || 5000 ;
9
9
this . lastEventId = null ;
10
10
this . lastIndexProcessed = 0 ;
@@ -209,11 +209,17 @@ class EventSource {
209
209
}
210
210
211
211
addEventListener ( type , listener ) {
212
+ if ( this . eventHandlers [ type ] === undefined ) {
213
+ this . eventHandlers [ type ] = [ ] ;
214
+ }
215
+
212
216
this . eventHandlers [ type ] . push ( listener ) ;
213
217
}
214
218
215
219
removeEventListener ( type , listener ) {
216
- this . eventHandlers [ type ] = this . eventHandlers [ type ] . filter ( ( handler ) => handler !== listener ) ;
220
+ if ( this . eventHandlers [ type ] !== undefined ) {
221
+ this . eventHandlers [ type ] = this . eventHandlers [ type ] . filter ( ( handler ) => handler !== listener ) ;
222
+ }
217
223
}
218
224
219
225
removeAllEventListeners ( type ) {
You can’t perform that action at this time.
0 commit comments