Split url-replacement to var-substitution to allow non-url subs#6257
Split url-replacement to var-substitution to allow non-url subs#6257mkhatib wants to merge 3 commits intoampproject:masterfrom
Conversation
jridgewell
left a comment
There was a problem hiding this comment.
LGTM, but I'm just assuming this is a copy-paste, right?
| installVarSubstitutionForEmbed(ampdoc, embedWin, varSource); | ||
| installServiceInEmbedScope(embedWin, 'url-replace', | ||
| new UrlReplacements(ampdoc, varSource)); | ||
| new UrlReplacements(ampdoc)); |
There was a problem hiding this comment.
Do we need to install installVarSubstitutionServiceForDoc?
There was a problem hiding this comment.
I am installing it for the embed scope, I think that should be enough no?
cc/ @avimehta
There was a problem hiding this comment.
I believe it should be enough because service for doc is installed elsewhere. otherwise, will it be okay to call it here again? it should be a noop if the service is already installed.
There was a problem hiding this comment.
What do you mean service for doc is installed elsewhere, you mean runtime.js call?
It would be a noop if we call it again here, but I don't understand why would we call it here since we haven't been installing it here before this change?
src/service/url-replacements-impl.js
Outdated
| } from './var-substitution-impl'; | ||
| import {varSubstitutionForDoc} from '../var-substitution'; | ||
| import { | ||
| VariableSource, |
There was a problem hiding this comment.
What are these being imported for?
There was a problem hiding this comment.
The gulp check-types throw errors because it doesn't know the Defs and the VariableSource type. I've noticed that we do add them to externs sometimes, should I do that instead?
This still breaks linting for example giving me VariableSource is defined but never used problem. So not sure how to best fix this.
There was a problem hiding this comment.
They types should be something like {../path/to/variable-source.VariableSource}?
|
Yes, this is mostly cut-paste with minimal changes to |
|
/cc @dvoytenko Initially when I created |
|
Also, A4AVariableSource currently "gets" the global variable source from url-replacements service. We can probably change it do directly request the service instead if we decide to go ahead with this PR. |
src/service/url-replacements-impl.js
Outdated
| VariableSource, | ||
| ResolverReturnDef, | ||
| SyncResolverDef, | ||
| } from './variable-source'; |
There was a problem hiding this comment.
Ditto for these imports.
There was a problem hiding this comment.
I tried this, didn't work because maybe defs are not exported, will export and try again.
|
If we have good use cases, I don't mind, but is there a real value to have it as a external service? |
|
Both Analytics and Forms (is it the forms installed with runtime or the forms extension?) will depend on now. Code size win? |
|
Forms extension. We also, wanted to make sure to separate general variable substitution from URL-specific replacements for specific extra protection for url-replacements (like the protocol mismatching). Forms will use var-subs inside hidden fields directly rather than the full URL. |
|
@jridgewell The url replacer is a core service so probably no code size effect. There's on issue with service proliferation: they are kind of hard to maintain when they need to be customized for embeds. Where we had a single service customized, now there are two that depend on each other in a bit confusing way. |
|
Do we just not do this and expose a URL-replacement API that is We really need a better way to handle embeds though. In my other PRs, it's confusing to know which context is this going to run in and how to handle the different contexts. I don't have a preference of which path we take in this PR, happy to close it and send a new one with new APIs to url-replacement, I'll leave the say to @jridgewell |
Defering to @dvoytenko. 😛 If we go the other route, I'd prefer the URL replacements to be the specialized method names. |
|
I'd keep one service and come up with the good new method names and deprecate the old ones and cleanup in a couple of weeks. |
|
So I am assuming naming is still going to be Suggestions for good API names?
|
|
This sounds good. To confirm though, do forms need string interpolation or just variable resolution? |
|
Sent a new PR #6323 |
As per this discussion moving var-sub to its own service.