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
Unify CacheState tracking for both legacy and remote video caching systems. #35252
Unify CacheState tracking for both legacy and remote video caching systems. #35252
Conversation
Hey @newmuis! These files were changed:
|
1960040
to
ba1113c
Compare
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.
Left nits for code readability
if (media.currentSrc === source.src && isCachedSource(source)) { | ||
return CacheState.CACHE; | ||
} | ||
if (isCachedSource(source)) { | ||
hasCachedSource = true; | ||
} |
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: To prevent defining the anon function, you could do
// All video caching mechanisms rely on HTMLSourceElements and never a src
// on the HTMLMediaElement as it does not allow for fallback sources.
const sources = toArray(media.querySelectorAll('source'));
let hasCachedSource = false;
for (const source of sources) {
if (source.hasAttribute('i-amphtml-video-cached-source')) {
// You can explain why this returns early so we understand when we look back at it (either this or the method documentation)
if (media.currentSrc === source.src) {
return CacheState.CACHE;
}
hasCachedSource = true;
}
}
return hasCachedSource ? CacheState.ORIGIN_CACHE_MISS : CacheState.ORIGIN;
Also, keeping the declaration of hasCachedSource
next to the loop will make it a bit easier to follow
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'd like to kindly push back on the nested condition :( I agree that removing the anon function is cool, but my brain is really bad at following nested conditions or else
statements (i.e. conditional conditions). This is why I always keep only one level of indentation, I found it to yield much much much easier to maintain code
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.
Still removed the anon function, thanks for the suggestion
ba1113c
to
edd0159
Compare
Unify
CacheState
tracking for both legacy and remote video caching systems.