Skip to content

Conversation

@sergiolenza
Copy link
Contributor

@sergiolenza sergiolenza commented May 7, 2018

  • Add default initializers
  • Use let and const instead var

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

The chat example can be updated with ES6 features like default params, constants (avoiding the use of var), and template literals.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

New behaviour

The chat example with these three features.

Other information (e.g. related issues)

@sergiolenza sergiolenza changed the title [docs] Improve the chat example with more ES6 features Improve the chat example with more ES6 features May 7, 2018
if (typeof options.prepend === 'undefined') {
options.prepend = false;
}
const addMessageElement = (el, options = { fade: true, prepend: false }) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wont work if null will be passed

@darrachequesne
Copy link
Member

@sergiolenza could you please review the comments made to the PR? Thanks a lot!

@sergiolenza
Copy link
Contributor Author

@sergiolenza could you please review the comments made to the PR? Thanks a lot!

Yes of course @darrachequesne.
I'll review it this weekend.
Thanks! 🙏

Copy link

@dasilvacontin dasilvacontin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes needed, but this is great, thank you! :)

let message = '';
if (data.numUsers === 1) {
message += "there's 1 participant";
message += `there's 1 participant`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string here should be single quotes, since there's no variable being insert (following the style of the rest of the page).

Suggested change
message += `there's 1 participant`;
message += 'there's 1 participant';

}

// Adds the visual chat message to the message list
const addChatMessage = (data, options) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a deleted line below that has no matching new line: options = options || {};.

Did you mean to add a default parameter for options here?

Suggested change
const addChatMessage = (data, options) => {
const addChatMessage = (data, options = {}) => {

const $el = $(el);
// Setup default options
if (!options) {
options = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest moving this to a default function parameter value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel to strongly about this change though, because there's additional "default options logic" that can't be moved into the parameter description, since you may define fade and not prepend, and you still want prepend to default to the value below (following the logic in this code).

connected = true;
// Display the welcome message
var message = "Welcome to Socket.IO Chat – ";
const message = 'Welcome to Socket.IO Chat – ';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(exhibit A of use of single quotes on string with non-parameter)

@darrachequesne darrachequesne merged commit 6b1d790 into socketio:master Jan 14, 2021
dzad pushed a commit to dzad/socket.io that referenced this pull request May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants