Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve jsdoc and minor changes in EventSource #3480

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading