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
⛓Linker PT 2 #17616
⛓Linker PT 2 #17616
Conversation
* before they are ready. | ||
* @private | ||
*/ | ||
initLinker_() { |
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 separate this into a separate file linker-manager.js
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.
const vendorConfig = this.config_['linkers'][name]; | ||
|
||
if (vendorConfig['enabled'] !== true) { | ||
user().warn(TAG, `linker config for ${name} is not enabled and` + |
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 should be a debugging message
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.
} | ||
|
||
const ids = vendorConfig['ids']; | ||
dev().assert(ids, |
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.
user()
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.
* @param {./amp-analytics.AmpAnalytics} analytics | ||
* @param {JsonObject} config | ||
*/ | ||
constructor(analytics, 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 avoid the reverse dependency on analytics
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.
* @param {!Element} element | ||
* @private | ||
*/ | ||
linkerCallback_(element) { |
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.
handleAnchorMutation_
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.
*/ | ||
init() { | ||
if (!this.config_['linkers']) { | ||
return; |
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.
can we have the optin check here to return early?
might be worth to just make a copy of enabled linkers in the 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.
Done.
} | ||
|
||
// See if any domains match. | ||
for (let i = 0; i < domains.length; i++) { |
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.
domains.indexOf(hostname) >= 0
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.
how about domains.includes()
src/service/navigation.js
Outdated
@@ -42,6 +42,11 @@ const EVENT_TYPE_CONTEXT_MENU = 'contextmenu'; | |||
/** @private @const {string} */ | |||
const ORIG_HREF_ATTRIBUTE = 'data-a4a-orig-href'; | |||
|
|||
/** @enum {number} */ | |||
export const Priority = { | |||
LINKER: 2, |
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.
ANALYTICS_LINKER
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.
import {Priority} from '../../../../src/service/navigation'; | ||
import {Services} from '../../../../src/services'; | ||
|
||
describe('Linkers', () => { |
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.
LinkerManager
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.
manager.init(); | ||
|
||
return Promise.all(manager.allLinkerPromises_).then(() => { | ||
const res1 = (manager.resolvedLinkers_['testLinker1']).split('~'); |
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.
avoid exposing resolvedLinkers_
to test, we can test the strings in a.href.
* Called on click on any anchor element. Adds linker param if a match for | ||
* given linker configuration. | ||
* @param {!Element} element | ||
* @private |
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.
visibleForTesting
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 tried this, but if you add @visibleForTesting
and it is used in the class it throws an error
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 think you will need to remove @private
and also the ending _
in method name.
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.
Got it. Done.
const linkerNames = Object.keys(this.config_['linkers']); | ||
|
||
if (!linkerNames.length) { | ||
return user().error(TAG, |
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.
It might worth to support syntax below to completely disable linkers:
{
linkers: false
}
So, we might not want to print this error.
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.
Should we check both? linkers: false
is good config, but linkers: {}
is bad?
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.
Actually I think this is covered by line 65. if (!this.config_['linkers'])
should cover the linkers: false
case and exit before this 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.
honestly i don't see strong reason to now allow linkers: {}
, especially with increasing binary size.
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.
ok removed.
}); | ||
}); | ||
|
||
if (this.allLinkerPromises_.length) { |
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.
nice!
* add priority * analytics changes * tests * example * fix import * types * move files * move files * lint * add enabled flag * add enabled to example * fix types * lint * comma * whitelist dep * add legacy opt-in * remove reverse dep * better warnings * lint * comments * includes * comments * make sure array * fix domains check * remove check * visible for test * bad rebase
Introduces the
Linker
logic intoamp-analytics
.