Skip to content

Commit 12b94b3

Browse files
committed
Removed unnecessary whitespace.
Moved reconnectAttempts to the read-only section of variables. Not sure why it was with the other settings. It is a read only setting, correct? Optimized the merging and defining of options and settings. Removed an unnecessary loop.
1 parent a1af998 commit 12b94b3

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

reconnecting-websocket.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,31 @@
6565

6666
// Default settings
6767
var settings = {
68-
6968
/** Whether this instance should log debug messages. */
7069
debug: false,
71-
7270
/** The number of milliseconds to delay before attempting to reconnect. */
7371
reconnectInterval: 1000,
74-
7572
/** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
7673
reconnectDecay: 1.5,
77-
78-
/** The number of attempted reconnects since starting, or the last successful connection. */
79-
reconnectAttempts: 0,
80-
8174
/** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
8275
timeoutInterval: 2000
8376
}
8477

85-
// Merge settings with passed options
86-
for (var key in options) {
87-
if (typeof settings[key] !== 'undefined' ) {
88-
settings[key] = options[key];
89-
}
90-
}
91-
92-
// Set object values from settings
78+
// Overwrite and define settings with options if they exist.
9379
for (var key in settings) {
94-
this[key] = settings[key];
80+
if (typeof options[key] !== 'undefined') {
81+
this[key] = options[key];
82+
} else {
83+
this[key] = settings[key];
84+
}
9585
}
9686

9787
// These should be treated as read-only properties
9888

9989
/** The URL as resolved by the constructor. This is always an absolute URL. Read only. */
10090
this.url = url;
91+
/** The number of attempted reconnects since starting, or the last successful connection. Read only. */
92+
this.reconnectAttempts = 0;
10193
/**
10294
* The current state of the connection.
10395
* Can be one of: WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED

0 commit comments

Comments
 (0)