Skip to content

Commit

Permalink
chore: improve jsdoc and minor changes in EventSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Aug 16, 2024
1 parent 6ee9ccd commit 7fbe53f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
17 changes: 9 additions & 8 deletions lib/web/eventsource/eventsource-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ const SPACE = 0x20
/**
* @typedef eventSourceSettings
* @type {object}
* @property {string} lastEventId The last event ID received from the server.
* @property {string} origin The origin of the event source.
* @property {number} reconnectionTime The reconnection time, in milliseconds.
* @property {string} [lastEventId] The last event ID received from the server.
* @property {string} [origin] The origin of the event source.
* @property {number} [reconnectionTime] The reconnection time, in milliseconds.
*/

class EventSourceStream extends Transform {
/**
* @type {eventSourceSettings}
*/
state = null
state

/**
* Leading byte-order-mark check.
Expand All @@ -63,7 +63,7 @@ class EventSourceStream extends Transform {
eventEndCheck = false

/**
* @type {Buffer}
* @type {Buffer|null}
*/
buffer = null

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

/**
* @param {object} options
* @param {eventSourceSettings} options.eventSourceSettings
* @param {Function} [options.push]
* @param {boolean} [options.readableObjectMode]
* @param {eventSourceSettings} [options.eventSourceSettings]
* @param {(chunk: any, encoding?: BufferEncoding | undefined) => boolean} [options.push]
*/
constructor (options = {}) {
// Enable object mode as EventSourceStream emits objects of shape
Expand Down Expand Up @@ -280,7 +281,7 @@ class EventSourceStream extends Transform {

/**
* @param {Buffer} line
* @param {EventStreamEvent} event
* @param {EventSourceStreamEvent} event
*/
parseLine (line, event) {
// If the line is empty (a blank line)
Expand Down
14 changes: 9 additions & 5 deletions lib/web/eventsource/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const defaultReconnectionTime = 3000

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

#url = null
#url
#withCredentials = false

/**
* @type {ReadyState}
*/
#readyState = CONNECTING

#request = null
Expand All @@ -98,7 +102,7 @@ class EventSource extends EventTarget {
/**
* Creates a new EventSource object.
* @param {string} url
* @param {EventSourceInit} [eventSourceInitDict]
* @param {EventSourceInit} [eventSourceInitDict={}]
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface
*/
constructor (url, eventSourceInitDict = {}) {
Expand Down Expand Up @@ -148,7 +152,7 @@ class EventSource extends EventTarget {
// 7. If the value of eventSourceInitDict's withCredentials member is true,
// then set corsAttributeState to Use Credentials and set ev's
// withCredentials attribute to true.
if (eventSourceInitDict.withCredentials) {
if (eventSourceInitDict.withCredentials === true) {
corsAttributeState = USE_CREDENTIALS
this.#withCredentials = true
}
Expand Down Expand Up @@ -189,7 +193,7 @@ class EventSource extends EventTarget {
/**
* Returns the state of this EventSource object's connection. It can have the
* values described below.
* @returns {0|1|2}
* @returns {ReadyState}
* @readonly
*/
get readyState () {
Expand Down

0 comments on commit 7fbe53f

Please sign in to comment.