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

Add Offscreen.prepare for constructor side effects #402

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

toasted-nutbread
Copy link

This is more consistent with other classes. This is probably another largely undocumented style of the project, but in most situations, constructor side effects are avoided and placed into a prepare function. prepare is also a place to put async code which doesn't work in a constructor, but that doesn't directly apply here right now.

@toasted-nutbread toasted-nutbread requested a review from a team as a code owner December 19, 2023 21:02
Copy link

✔️ No visual differences introduced by this PR.

View Playwright Report (note: open the "playwright-report" artifact)

Copy link
Collaborator

@djahandarie djahandarie left a comment

Choose a reason for hiding this comment

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

LGTM. Should we also turn on the https://eslint.org/docs/latest/rules/no-new lint? It would have (sort of) caught this. Ideally we'd have a stronger lint which checks for global variable access within constructors too, but I guess that doesn't exist.

@djahandarie djahandarie added this pull request to the merge queue Dec 20, 2023
Merged via the queue into yomidevs:master with commit ad94a56 Dec 20, 2023
5 checks passed
@djahandarie djahandarie added the kind/meta The issue or PR is meta label Dec 20, 2023
@toasted-nutbread
Copy link
Author

I'll turn it on since in general it's consistent with the style of the project thus far.

Ideally we'd have a stronger lint which checks for global variable access within constructors too, but I guess that doesn't exist.

document and window would run into issues with this, so it's not necessarily the use of globals itself that's a problem.

I've had some thoughts on things related to this before, basically disallowing all global access throughout the project with limited exceptions, including environment globals like chrome, window, document, etc. and instead passing them around more explicitly. This is potentially overkill in some ways, but I could also see it being interesting for some other reasons. I don't really plan on doing this for the time being though.

It's also worth noting that the no-constructor-side-effects (or at least minimal effects) that this project style aims for is not even something that is mandatory when designing software, just something that was chosen. I've seen other JS libraries have plenty of constructor side effects, and it can sometimes simplify API usage overall. So my change here was mainly motivated by consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/meta The issue or PR is meta
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants