Skip to content

Commit 5af9963

Browse files
authored
chore: improve jsdoc and minor changes in EventSource (#3480)
1 parent 1c5c954 commit 5af9963

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lib/web/eventsource/eventsource-stream.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ const SPACE = 0x20
3535
/**
3636
* @typedef eventSourceSettings
3737
* @type {object}
38-
* @property {string} lastEventId The last event ID received from the server.
39-
* @property {string} origin The origin of the event source.
40-
* @property {number} reconnectionTime The reconnection time, in milliseconds.
38+
* @property {string} [lastEventId] The last event ID received from the server.
39+
* @property {string} [origin] The origin of the event source.
40+
* @property {number} [reconnectionTime] The reconnection time, in milliseconds.
4141
*/
4242

4343
class EventSourceStream extends Transform {
4444
/**
4545
* @type {eventSourceSettings}
4646
*/
47-
state = null
47+
state
4848

4949
/**
5050
* Leading byte-order-mark check.
@@ -63,7 +63,7 @@ class EventSourceStream extends Transform {
6363
eventEndCheck = false
6464

6565
/**
66-
* @type {Buffer}
66+
* @type {Buffer|null}
6767
*/
6868
buffer = null
6969

@@ -78,8 +78,9 @@ class EventSourceStream extends Transform {
7878

7979
/**
8080
* @param {object} options
81-
* @param {eventSourceSettings} options.eventSourceSettings
82-
* @param {Function} [options.push]
81+
* @param {boolean} [options.readableObjectMode]
82+
* @param {eventSourceSettings} [options.eventSourceSettings]
83+
* @param {(chunk: any, encoding?: BufferEncoding | undefined) => boolean} [options.push]
8384
*/
8485
constructor (options = {}) {
8586
// Enable object mode as EventSourceStream emits objects of shape
@@ -280,7 +281,7 @@ class EventSourceStream extends Transform {
280281

281282
/**
282283
* @param {Buffer} line
283-
* @param {EventStreamEvent} event
284+
* @param {EventSourceStreamEvent} event
284285
*/
285286
parseLine (line, event) {
286287
// If the line is empty (a blank line)

lib/web/eventsource/eventsource.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const defaultReconnectionTime = 3000
2828

2929
/**
3030
* The readyState attribute represents the state of the connection.
31-
* @enum
31+
* @typedef ReadyState
32+
* @type {0|1|2}
3233
* @readonly
3334
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-readystate-dev
3435
*/
@@ -80,9 +81,12 @@ class EventSource extends EventTarget {
8081
message: null
8182
}
8283

83-
#url = null
84+
#url
8485
#withCredentials = false
8586

87+
/**
88+
* @type {ReadyState}
89+
*/
8690
#readyState = CONNECTING
8791

8892
#request = null
@@ -98,7 +102,7 @@ class EventSource extends EventTarget {
98102
/**
99103
* Creates a new EventSource object.
100104
* @param {string} url
101-
* @param {EventSourceInit} [eventSourceInitDict]
105+
* @param {EventSourceInit} [eventSourceInitDict={}]
102106
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface
103107
*/
104108
constructor (url, eventSourceInitDict = {}) {
@@ -148,7 +152,7 @@ class EventSource extends EventTarget {
148152
// 7. If the value of eventSourceInitDict's withCredentials member is true,
149153
// then set corsAttributeState to Use Credentials and set ev's
150154
// withCredentials attribute to true.
151-
if (eventSourceInitDict.withCredentials) {
155+
if (eventSourceInitDict.withCredentials === true) {
152156
corsAttributeState = USE_CREDENTIALS
153157
this.#withCredentials = true
154158
}
@@ -189,7 +193,7 @@ class EventSource extends EventTarget {
189193
/**
190194
* Returns the state of this EventSource object's connection. It can have the
191195
* values described below.
192-
* @returns {0|1|2}
196+
* @returns {ReadyState}
193197
* @readonly
194198
*/
195199
get readyState () {

0 commit comments

Comments
 (0)