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
Subscriptions: Add action execution and rendering actions #13790
Subscriptions: Add action execution and rendering actions #13790
Conversation
prateekbh
commented
Mar 3, 2018
- Adds event listener for actions
- Adds rendering logic for platforms
- Adds methods for Subscription platform Interface
…mp-subs-actions
…mp-subs-actions
…mp-subs-action-listener
this.ampdoc_ = ampdoc; | ||
|
||
/** @private @const */ | ||
this.document_ = this.ampdoc_.win.document; |
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.
You should almost never use document. Instead, there's ampdoc.getRootNode()
and family.
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 expr = candidate.getAttribute('subscriptions-display'); | ||
if (expr && evaluateExpr(expr, entitlements)) { | ||
candidate.setAttribute('i-amphtml-subs-display', ''); | ||
} |
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.
If you do else {candidate.removeAttribute(...)}
this method will become reentrant.
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 believe that this should be a part of a separate deactivate
method which would be called for all platforms which are not selected. WDYT?
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.
Probably a good idea. Feel free to proceed with that idea in a separate PR.
* @private | ||
*/ | ||
initializeListeners_() { | ||
this.document_.addEventListener('click', e => { |
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.
Ditto. Only add listeners to ampdoc.getRootNode()
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 actionExecution = this.actions_.execute(action); | ||
actionExecution.then(result => { | ||
if (result) { | ||
this.getEntitlements(); |
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.
Would this have any affect on rendering or such? Also, you may want to execute this call via the top-level service b/c changing of entitlements here could result in selecting a new platform... Maybe something like: service.reAuthorizePlatform(this)
or such?
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.
yes, added a todo which will resolve with the actio delegation PR as both need a service interface
* Renders the UI specific to the platform | ||
*/ | ||
render() { | ||
|
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.
remove extra line
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
/** | ||
* Renders the UI specific to the platform | ||
*/ | ||
render() { |
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.
Implement right away on google subscriptions: even if it's just an empty method. But I feel like the name is not broad enough. Maybe activate()
?
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
…mp-subs-action-listener
…#13790) * fix animating circle fixed position * adding selectPlatform method * WIP actions * adding tests * fixing comments * WIP action delegation * renders the platform actions * adding tests * fixing comments