amphtml: Migrate the use of user().error() to this.user().error()
What’s the issue
The plan is to eliminate user().error() call, and instead using:
this.user().error(),
or:
this.ampdoc().user().error()
Initial problem
- I’m working on the user-error-reporting project, which reports user errors to publishers so that they can act upon.
- In order to exclude errors generated from iframe embed, we agreed to pass in a base-element whenever calling user() (see A4A errors in the doc):
user(this).error()
. - Currently, I’m having an {Element} passed in (see isFromEmbed). The element is now optional.
- In the end, we’d want to use {BaseElement} instead of {Element}, and make it a required param when using user().
- However, base-element.js and log.js will have circular dependency if I introduce base-element in my code in log.js:
element.ownerDocument.defaultView != ampdoc.win
. In addition, not every class/file has a base element to pass around.
Possible approach
- In base-element.js, introduce another user() field:
user() { return user(this.element); }
This would eliminate the circular dependency. - Also introduce similar user() field in amp-doc, so that whenever base-element is not available, we can use amp-doc to check:
this.ampdoc().user().error()
Discuss
- This will change everyone’s use of user() and possibly coding style (passing by ampdoc, etc.). Therefore we’re looking for everyone’s opinion on this design.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (16 by maintainers)
ampdoc.user()
is definitely fine.element.user()
is mostly a shortcut, but we need to see if we ever have user errors before element is attached to DOM, where ampdoc is not available. I don’t know if any global services send user errors. Hopefully not.