-
Notifications
You must be signed in to change notification settings - Fork 430
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
Support multiple calls to onINP()
with different config options
#583
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks to work but I'm really, really, really hating the $ thing. I don't see how this is maintainable going forward. I'm already confused as to which variables should have a $ and which shouldn't (see comment below).
And this has just gets MORE complicated in #585 as we need to roll this pattern out to LCP and CLS :-(
There surely must be a better way to have separate entryPreProcessingCallbacks
values (maybe keyed by a unique id created at each onINP
instantiation?).
src/lib/InteractionManager.ts
Outdated
id: number; | ||
entries: PerformanceEventTiming[]; | ||
$latency: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are only two of these public, and one not? Seems weird to mix and match public and private names in the same interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't think of the $
prefix and representing public or private (at least in the traditional sense of those words)—only whether or not the symbol will be mangled by terser. All of these symbols are "public" in the strict sense (in that they are accessible outside of their class), but "private" to the package (in that no consumer of the web-vitals
library can access these methods).
As for why some of them have the $
prefix and some don't, the only reason they all don't is because the property names id
, entries
are already part of the public Metric
API, and so the library compresses better if we don't mangle those symbols but instead reuse the existing dictionary entry for them.
We can probably add a comment in the code to avoid that confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh that's what I wasn't getting. Definitely needs a comment to explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philipwalton why $
and not _
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_
is more common for internal variable names in my experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had _
, but then I was concerned that was confusing since a _
prefix typically implies private in the traditional sense (which this is not).
But I'm happy to move back to that if you'd all prefer it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well _
is more a convention of "internal", than necessarily private. The newer #
would strictly mean private. So I think _
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched from $
to _
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't feel strongly, but $
makes me think, "oh no, what weird thing are they doing with their build" while _
I think, "well, that's not exactly 'private', but close enough" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup me too.
I also don’t think it needs documented as much with _
because it’s a more well-known pattern.
See my other comment for an explanation as to why some have the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the switch to _
I feel more comfortable with this since it’s a more used pattern.
Fixes #582.
This PR updates the
interactions.ts
logic to encapsulate it in a class that can be instantiated peronINP()
call. It also moves most of the functions in theattribution/onINP.ts
file inside of theonINP()
closure, to keep all of the variables local to eachonINP()
call.The main downside of this PR is it increases the bundle size of the library (since object properties don't minify as well as instance variables), but I added an additional terser config option to mangle object properties that begin with a
$
character, which negates much of the increased size (at the expense of being a bit annoying to write).