Skip to content

Move extractSize to a separate hook#10127

Merged
keithwrightbos merged 6 commits intomasterfrom
size-hook
Jun 28, 2017
Merged

Move extractSize to a separate hook#10127
keithwrightbos merged 6 commits intomasterfrom
size-hook

Conversation

@taymonbeal
Copy link
Copy Markdown
Member

Determining the size of a Fast Fetch creative is now done through its own overridable method in AmpA4A. This will facilitate the deprecation of extractCreativeAndSignature, which in turn will facilitate having two different signature schemes controlled by a client-side experiment.

One of the PRs that #9040 is being split into. Related to #7618.

.then(adResponse => {
expect(adResponse).to.deep.equal(
{creative, signature: base64UrlDecodeToBytes('AQAB')});
expect(impl.extractSize(headers)).to.deep.equal(size);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: indent is off here.

@@ -649,20 +654,23 @@ export class AmpA4A extends AMP.BaseElement {
// This block returns the ad creative and signature, if available; null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's update these comments to reflect that size will also be passed down through here.

expect(loadExtensionSpy.withArgs('amp-analytics')).to.be.called;
signature: base64UrlDecodeToBytes('AQAB'),
});
expect(impl.extractSize(headers)).to.deep.equal(size);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: indent here as well.

if (!headerValue) {
return null;
}
if (!(/[0-9]+x[0-9]+/.test(headerValue))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're going to do a RegExp, why not just capture the values out of the regexp and save the split?

if (size) {
this.size_ = size;
} else {
size = this.size_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This always felt odd to me. Why not have this return null if its not in the headers and move the logic to when we apply sizing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll be honest, I don't really understand how this code works. Do you mean the call to setStyles in onCreativeRender? Where would that code get the information about what size to use, if it wasn't set here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK no need to address in this PR.

if (size) {
this.size_ = size;
} else {
size = this.size_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK no need to address in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants