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

amp-bind: Support bindings in fixed layer #16130

Merged
merged 17 commits into from
Jun 21, 2018

Conversation

dreamofabear
Copy link

@dreamofabear dreamofabear commented Jun 18, 2018

Fixes #14888.

  • Instead of only scanning the body on initialization, scan the entire document which includes fixed layer.

@dreamofabear
Copy link
Author

/to @jridgewell For review of fixed layer. Will add tests if you think this approach is ok.

return this.initialize_(body, head && elementByTag(head, 'title'));
const title = head && elementByTag(head, 'title');
const fixedLayer = this.viewport_.getFixedLayerContainer();
return this.initialize_(body, fixedLayer, title);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use document as the root, instead of body? Then you don't need to be aware of the fixed layer.

Copy link
Author

Choose a reason for hiding this comment

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

I wanted to avoid scanning the head unnecessarily, but this is a lot cleaner. Thanks.

// Values start at 801 for easier code searchability and to avoid conflation
// with HTTP status codes.
DOM_UPDATE: 801,
// The following codes are only used for testing.
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we depend on the built signal for owner elements.

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks.

ERROR: 'amp:error',
// Values start at 801 for easier code searchability and to avoid conflation
// with HTTP status codes.
DOM_UPDATE: 801,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing to numbers?

Copy link
Author

@dreamofabear dreamofabear Jun 20, 2018

Choose a reason for hiding this comment

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

Travis build failed due to bundle-size. This saves 0.03KB. 😄 We'll end up doing the same with error messages which should save a bunch more.

Had to change back to strings to avoid conversion for event type.

Copy link
Author

Choose a reason for hiding this comment

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

Actually realized FixedLayer doesn't need to dispatch DOM_UPDATE (at least for amp-bind) since it doesn't add new elements but just moves them on/off the transfer layer.

Still would be nice to keep this change for a small size reduction.

@aghassemi
Copy link
Contributor

nice, I think this will also fix #15828 /cc @cvializ

LOAD_START: 'e5',
LOAD_END: 'e6',
ERROR: 'e7',
VISIBILITY_CHANGE: 'e8',
Copy link
Contributor

Choose a reason for hiding this comment

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

Ads uses this one.

Copy link
Author

Choose a reason for hiding this comment

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

I only saw usage in test code but upon closer inspection it's actually externally visible. 🤦‍♂️

Additionally, one can observe the amp:visibilitychange on the window object to be notified about changes in visibility.

https://github.com/ampproject/amphtml/blob/master/ads/README.md#page-visibility

Updated the unit test to use the string literal to catch this.

ERROR: 'amp:error',
// Use short, unique strings to reduce bundle size impact.
BUILT: 'e1',
DOM_UPDATE: 'e2',
Copy link
Contributor

Choose a reason for hiding this comment

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

Date picker, lightbox, list, forms, access, and FX uses this one.

LOAD_END: 'amp:load:end',
ERROR: 'amp:error',
// Use short, unique strings to reduce bundle size impact.
BUILT: 'e1',
Copy link
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 30b is worth changing these, especially once we strip out the testing ones. Error messages are a special case because they are usually very long messages, these aren't.

Copy link
Author

Choose a reason for hiding this comment

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

Fair enough, don't feel strongly enough to fight ya. 😉

@dreamofabear
Copy link
Author

@jridgewell Ping. :)

@dreamofabear dreamofabear merged commit b1e5115 into ampproject:master Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-bind: Support bindings on fixed layer elements
4 participants