Skip to content

Wait for amp selector to load before submissions#6951

Closed
mkhatib wants to merge 3 commits intoampproject:masterfrom
mkhatib:wait-for-amp-selector
Closed

Wait for amp selector to load before submissions#6951
mkhatib wants to merge 3 commits intoampproject:masterfrom
mkhatib:wait-for-amp-selector

Conversation

@mkhatib
Copy link
Copy Markdown
Contributor

@mkhatib mkhatib commented Jan 9, 2017

Fixes #6927

This depends on #6929

const usedDeps = this.form_.querySelectorAll(EXTERNAL_DEPS.join(','));
const depsDict = {};
const depsPromises = [];
for (let i = usedDeps.length - 1; i >= 0; i--) {
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.

you should not have to loop through all matching elements.

You can loop through EXTERNAL_DEPS and check of getElementsByTagName(tag).length > 0 then wait for the tag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess now we only have one dependency getElementsByTagName is fine. Not sure if querySelectorAll would be faster than multiple getElementsByTagName in the future.

Will update this to use getElementsByTagName.

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.

you will still have to do a tagName read with queryseletorall in a loop (atleast one per the tag in the array). I still think what i suggested is slightly better and clean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@mkhatib mkhatib force-pushed the wait-for-amp-selector branch from 3e9e1b5 to 096abbd Compare January 13, 2017 23:05
@mkhatib
Copy link
Copy Markdown
Contributor Author

mkhatib commented Jan 13, 2017

@camelburrito PTAL 👀

const tagName = EXTERNAL_DEPS[i];
const depIsUsed = this.form_.getElementsByTagName(tagName).length !== 0;
if (depIsUsed && depsDict[tagName] === undefined) {
// TODO(mkhatib, #7032): Implement a way to wait for an element to be built to
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dvoytenko I prefer to do this in a separate PR if that's ok. lmk.

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.

I think that the implementation would be drastically different and we should consider doing build promise work first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sgtm. will leave this PR until I have something for the build promise.

this.actions_.installActionHandler(
this.form_, this.actionHandler_.bind(this));
// Wait for amp-selector to finish loading if the current form is using it.
this.whenDependenciesReady_().then(() => {
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.

I'm not sure it makes sense to wait to install action handler here, esp since we have other listeners that could override the behavior. Should, instead, action handler be installed right away, but block on dependencies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

esp since we have other listeners that could override the behavior

You mean other submit listeners? This would still be very similar situation with blocking on dependencies there are still other listeners.

If you meant other action handlers yeah if some other code install an action listener on the form element these submit events will be gone from the queue.

const tagName = EXTERNAL_DEPS[i];
const depIsUsed = this.form_.getElementsByTagName(tagName).length !== 0;
if (depIsUsed && depsDict[tagName] === undefined) {
// TODO(mkhatib, #7032): Implement a way to wait for an element to be built to
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.

I think that the implementation would be drastically different and we should consider doing build promise work first.

*/
function checkUserValidity(element, propagate = false) {
// If this is not a field type with checkValidity don't do anything.
if (!element.checkValidity) {
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.

Is the assumption that amp-selector somehow will implement this interface? Do we have issues that would track this work? In particular required is very sensible for amp-selector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I filed an issue to track this #6930

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.

3 participants