Skip to content

refactor: flatten nested if-else blocks - #6

Open
cades wants to merge 5 commits into
developit:masterfrom
cades:refactor/flatten-blocks
Open

cades wants to merge 5 commits into
developit:masterfrom
cades:refactor/flatten-blocks

Conversation

@cades

@cades cades commented Jan 10, 2018

Copy link
Copy Markdown

apply "return early, avoid else" practice to make code simple and easy to read

@developit

Copy link
Copy Markdown
Owner

Need to check the effect on filesize, but I'd imagine this is a savings! (due to uglify better optimizing early returns than nested conditionals)

Comment thread src/index.js Outdated
return;
}

Promise.resolve(() => method.apply(null, data.params))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This creates a Promise with a value resolved to the function itself. See below:
screen shot 2018-01-11 at 10 01 02 am

@developit

developit commented Jan 12, 2018 •

Copy link
Copy Markdown
Owner

hey @cades - that nested .then() is important - without it, an exception thrown by the method being called won't be passed back via RPC, it'll just be emitted as an error in the worker.

@cades

cades commented Jan 12, 2018

Copy link
Copy Markdown
Author

@developit thanks for point that out! Seems my knowledge to Promise is not promising 😂
BTW, if you think it is OK to accept this PR, I'm willing to squash these commits into a single commit before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants