-
Notifications
You must be signed in to change notification settings - Fork 29
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
control non amp pages via amp-sw #28
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.
Left a few pieces of feedback.
super(config); | ||
private allowedPages_: Array<RegExp>; | ||
|
||
constructor(config: { |
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.
Let's make the config an interface defined before the default class.
Also if it's by default required your can force all fields to be optional via TS syntax. Partial<Config>
. (https://github.com/Microsoft/TypeScript/blob/ee25cdecbca49b2b5a290ecd65224f425b1d6a9c/lib/lib.es5.d.ts#L1354)
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.
Also, since this extends an interface from Workbox, let's make sure we're extending the type provided by Workbox.
If Workbox isn't providing the interface type, let's fix their definitions.
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.
Comment 1 is fixed.
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.
Re Comment 2: The next version of Workbox is being written in TS, so that should solve the problem
}) { | ||
const { allowedNonAMPPages, ...pluginConfig } = config; | ||
super(pluginConfig); | ||
if (allowedNonAMPPages && Array.isArray(allowedNonAMPPages)) { |
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.
Possible to make this early exit pattern instead of checking existance in successive condition checks?
if (allowedNonAMPPages) {
if (!Array.isArray(allowedNonAMPPages)) {
throw new TypeError('allowedNonAMPPages should be an array of RegExp');
}
this.allowedPages_ = allowedNonAMPPages;
}
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.
done
if (currentTestUrl.test(clonedResponse.url)) { | ||
return response; | ||
} | ||
} |
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.
Might also consider an Array.find
.
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.
fixed with Array.some
as we were not using the returned object
@@ -30,6 +30,7 @@ export type DocumentCachingOptions = { | |||
timeoutSeconds?: Number; | |||
maxDocumentsInCache?: Number; | |||
maxAgeSecondsforDocumentsInCache?: Number; | |||
allowedNonAMPPages?: Array<RegExp>; |
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.
Investigate extending the Plugin interfaces to create the DocumentCachingOptions 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.
The reason why we cannot do this is because our keys do not match with the Plugin's config keys.
e.g. MaxExtries makes sense for workbox but for us the same key is known as MaxDocumentsInCache
so the extends
wouldn't work here
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.
Makes sense, thanks for investigating. Might recommend a comment or similar.
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.
done
super(pluginConfig); | ||
if (allowedNonAMPPages) { | ||
if (!Array.isArray(allowedNonAMPPages)) { | ||
throw new TypeError('allowedNonAMPPages should be an array of RegExp'); |
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.
If the value is a single RegExp
should this handle 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.
I guess just enforcing this to always be an array should make this intuitive enough for everyone, plus lesser switch cases around typeof
would keep the code straight forward
@@ -30,6 +30,7 @@ export type DocumentCachingOptions = { | |||
timeoutSeconds?: Number; | |||
maxDocumentsInCache?: Number; | |||
maxAgeSecondsforDocumentsInCache?: Number; | |||
allowedNonAMPPages?: Array<RegExp>; |
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.
Makes sense, thanks for investigating. Might recommend a comment or similar.
fixes #17
allowedNonAMPPages:Array<RegExp>
config todocumentCachingOptions
.