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

Small simplifications #3243

Closed

Conversation

Zearin
Copy link
Contributor

@Zearin Zearin commented Apr 5, 2024

These are an assortment of small tweaks.

My goal was to make these bits of code easier to understand at a glance. There’s plenty of subjectivity in that, to be sure.

Some of these make use of Javascript features that were not available a few years ago. (Both syntax and APIs of built-in objects.) Hopefully, I applied them in a way that makes it easier to understand each block of code. Since Eleventy v3 is still in alpha, I thought this would be a good time to introduce them, since they are supported pretty much everywhere and a major version increment doesn’t have to worry about breaking compatibility.

src/Eleventy.js Outdated Show resolved Hide resolved
@Zearin Zearin force-pushed the refactor/small-simplifications-best-bits branch from 1af79d9 to 8f23e8f Compare April 9, 2024 21:09
@Zearin
Copy link
Contributor Author

Zearin commented Apr 9, 2024

Updated based on your feedback.

Whatcha think?

@Zearin Zearin requested review from zachleat and uncenter April 9, 2024 22:53
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. I dunno what I was mis-remembering…maybe it was from when I used to work in Python? 🤷‍♂️

I’ll fix it shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c69fe27.

@Zearin Zearin requested a review from uncenter April 10, 2024 21:02
src/Eleventy.js Show resolved Hide resolved
src/Eleventy.js Outdated Show resolved Hide resolved
src/EleventyExtensionMap.js Show resolved Hide resolved
Some tweaks to (hopefully) make some loops a little faster to grok
A little use of the newer optional chaning operator to make some repetetive conditionals slightly faster to read.
Some targeted use of `.some()` and `.includes()` to convey the intention in compact fashion.
Some rewrites involving `Set`s, often involved in making it easier to grok what’s populating the set at a glance.
The standard functional tools for manipulating Arrays (usually `.map()` and `.filter()`) make it easy to write some code that reads a little bit like a pipeline.

Some small rewrites can make these even easier to read. If the arrow function is short enough, using the single-line syntax can make it less  noisy by avoiding the need for braces `{`|`}` or `return`.

Using the static methods _directly_ for the callback is even better, since it’s not even necessary to use an anonymous arrow function or name any arguments.
@Zearin Zearin force-pushed the refactor/small-simplifications-best-bits branch from bf63527 to 00c5180 Compare April 10, 2024 23:15
@Zearin Zearin requested a review from uncenter April 10, 2024 23:16
@Zearin
Copy link
Contributor Author

Zearin commented Apr 13, 2024

I messed up on a rebase. 🤦‍♂️ I’ll redo this in a new PR.

@Zearin Zearin closed this Apr 13, 2024
@Zearin Zearin deleted the refactor/small-simplifications-best-bits branch April 14, 2024 14:02
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.

None yet

3 participants