developit / workerize

🏗️ Run a module in a Web Worker.
https://github.com/developit/workerize-loader
4.35k stars 91 forks source link

refactor: flatten nested if-else blocks #6

Open cades opened 6 years ago

cades commented 6 years ago

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

developit commented 6 years ago

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)

developit commented 6 years ago

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 commented 6 years ago

@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.