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

Add getHtml support in AmpContext API. #12423

Merged
merged 12 commits into from Dec 14, 2017
Merged

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Dec 12, 2017

Closes #12333

@@ -147,6 +163,18 @@ function createIframeWithApis(fixture) {
return poll('wait for new IO entry', () => {
return lastIO != null;
});
}).then(() => {
let resolver;
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified a lot:

// ...
}).then(() => new Promise((resolve, reject) => {
  iframe.contentWindow.context.getHtml('a', ['href'], content => {
    if (content == '<a href="http://test.com/test">Test link</a>') {
      resolve();
    } else {
      reject(new Error('Invalid getHtml result: ' + content));
    }
  });
}));

I also made changes for a couple of nits here:

  1. No need for strict equality when comparing against a non-empty string.
  2. message should say "invalid" rather than "incorrect".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Done.

@@ -147,6 +163,16 @@ function createIframeWithApis(fixture) {
return poll('wait for new IO entry', () => {
return lastIO != null;
});
}).then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

how about inlining the return as part of the fat arrow function? :)

.then(() => new Promise(resolve, reject) => {
  // ...
}));

Nit: Invalid getHtml result would be a better message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

3p/ampcontext.js Outdated
@@ -177,6 +180,31 @@ export class AbstractAmpContext {
return unlisten;
};

/**
* Send message to runtime requesting HTML snippet of the parent window.
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, missed this before.

A few doc nits:

  1. Description leaks implementation details. How about Requests HTML snippet from the parent window.?
  2. {!Array<string>}
  3. How about replacing an array of tag attributes to be left in the stringified HTML with Whitelist of attributes to be kept in the returned HTML string.
  4. Callback to be invoked with the HTML string as the first parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. How about now?

@lannka lannka merged commit 2e6f38b into ampproject:master Dec 14, 2017
@lannka lannka deleted the getHtml branch December 14, 2017 19:42
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
* Add getHtml support in AmpContext API.

* lint

* revert fakead3p examples

* revert fakead3p examples

* revert fakead3p examples

* More linter

* Address comments

* Address comments

* Address comments

* Address comments
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.

None yet

4 participants