Skip to content
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

Fix AmpAdApiHandler type check #5722

Merged
merged 7 commits into from Oct 20, 2016
Merged

Fix AmpAdApiHandler type check #5722

merged 7 commits into from Oct 20, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Oct 20, 2016

AmpAdApiHandler is calling AmpAd3PImpl or AmpA4A method, however BaseElement don't have these method type so there will be type check errors. This is to fix the issue by restricting the AmpAdApiHandler baseInstance to be either AmpAd3pImpl or AmpA4. This also helps for code sharing #5356 later, so that I can access their UIHandler without type check errors.
PTAL

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

LGTM

* @param {!Element} element
* @param {function()=} opt_noContentCallback
*/
constructor(baseInstance, element, opt_noContentCallback) {
/** @private {!AMP.BaseElement} */

/** @private {!./amp-ad-3p-impl.AmpAd3PImpl|../../amp-a4a/0.1/amp-a4a.AmpA4A}*/
Copy link
Contributor

Choose a reason for hiding this comment

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

The duplicated type hint here shouldn't be necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need this. Even if CC managed to infer the type from the param, without a @private it won't consider it an instance variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i think this.baseInstance_ still need type check, like we still put a @private {!Element} beforethis.element_`.

Copy link
Contributor

Choose a reason for hiding this comment

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

@private's not a type hint, we need it. But the {...} stuff should be inferred, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. it did work with only @private. Hmmm the type check thing confused me so much 😢

@@ -32,12 +32,13 @@ const TIMEOUT_VALUE = 10000;
export class AmpAdApiHandler {

/**
* @param {!AMP.BaseElement} baseInstance
* @param {!./amp-ad-3p-impl.AmpAd3PImpl|../../amp-a4a/0.1/amp-a4a.AmpA4A} baseInstance
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be {!...|!...} ? (note the second ! for the second union type)

Copy link
Contributor

Choose a reason for hiding this comment

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

(same for the instance variable one)

* @param {!Element} element
* @param {function()=} opt_noContentCallback
*/
constructor(baseInstance, element, opt_noContentCallback) {
/** @private {!AMP.BaseElement} */

/** @private {!./amp-ad-3p-impl.AmpAd3PImpl|../../amp-a4a/0.1/amp-a4a.AmpA4A}*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need this. Even if CC managed to infer the type from the param, without a @private it won't consider it an instance variable.

@@ -161,9 +161,10 @@ export class AmpA4A extends AMP.BaseElement {
/** @private {?string} */
this.experimentalNonAmpCreativeRenderMethod_ = null;

this.lifecycleReporter_ = getLifecycleReporter(this, 'a4a');
/** @public {!../../../ads/google/a4a/performance.AmpAdLifecycleReporter|!../../../ads/google/a4a/performance.NullLifecycleReporter} */
Copy link
Contributor

Choose a reason for hiding this comment

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

@public isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -84,8 +84,10 @@ export class AmpAd3PImpl extends AMP.BaseElement {
/** @private {?Promise} */
this.layoutPromise_ = null;

this.lifecycleReporter_ = getLifecycleReporter(this, 'amp');
this.lifecycleReporter_.sendPing('adSlotBuilt');
/** @public {!../../../ads/google/a4a/performance.AmpAdLifecycleReporter|!../../../ads/google/a4a/performance.NullLifecycleReporter} */
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto.

@zhouyx zhouyx merged commit 4198f8e into ampproject:master Oct 20, 2016
@zhouyx zhouyx deleted the closure branch October 20, 2016 21:10
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants