Proxying the form to call the prototype methods/properties#6720
Proxying the form to call the prototype methods/properties#6720dvoytenko merged 6 commits intoampproject:masterfrom
Conversation
| } | ||
| }); | ||
|
|
||
| form['$p'] = proxy; |
There was a problem hiding this comment.
@dvoytenko just double checking, should be $p and not $proxy?
There was a problem hiding this comment.
Yes. Was thinking about changing it to $p since it's a lot shorter.
|
|
||
|
|
||
| /** | ||
| * @param {!HTMLFormElement} form |
There was a problem hiding this comment.
This docs for this should be the URL to the Medium post about it :)
There was a problem hiding this comment.
Until then we will need something here.
| * @return {!Object} | ||
| */ | ||
| export function installFormProxy(form) { | ||
| const proxy = {}; |
There was a problem hiding this comment.
Can we have a proxy prototype (that we initialize on the first form?
The proxy instance would then just have a private field like instance_ and the getters would access the form through this.instance_
| */ | ||
| function FormProxy(form) { | ||
| /** @private @const {!HTMLFormElement} */ | ||
| this.form = form; |
cramforce
left a comment
There was a problem hiding this comment.
LG, but add extensive docs.
| const properties = win.Object.getOwnPropertyDescriptors(prototype); | ||
| for (const name in properties) { | ||
| if (win.Object.hasOwnProperty(FormProxyProto, name) || | ||
| name == 'constructor') { |
There was a problem hiding this comment.
This is redundant, it'll never be true without the proceeding conditional being true.
| for (const name in properties) { | ||
| if (win.Object.hasOwnProperty(FormProxyProto, name) || | ||
| name == 'constructor') { | ||
| if (win.Object.hasOwnProperty(FormProxyProto, name)) { |
There was a problem hiding this comment.
Oh, and this should be .call, and really Object.prototype.hasOwnProperty.call. Or we created a helper.
…t#6720) * TBD: proxying the form to call the prototype methods/properties * tests * FormProxy.prototype * docs * use Object.prototype.hasOwnProperty * fixes
…t#6720) * TBD: proxying the form to call the prototype methods/properties * tests * FormProxy.prototype * docs * use Object.prototype.hasOwnProperty * fixes
To be discussed: any better way of doing this?