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

refactoring code to combine if statements and reduce cognitive load #100

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/socket.io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function deserializePayload(payload) {
async function onMessage(socket, payload) {
const { event, params, callback } = payload;
try {
// combine if statements to reduce cognitive load
// to reduce cognitive load
if (!event) {
return winston.warn('[socket.io] Empty method name');
}
Expand All @@ -166,7 +168,6 @@ async function onMessage(socket, payload) {
const escapedName = validator.escape(typeof event);
return callback({ message: `[[error:invalid-event, ${escapedName}]]` });
}

const parts = event.split('.');
const namespace = parts[0];
const methodToCall = parts.reduce((prev, cur) => {
Expand Down