Skip to content

Commit

Permalink
deprecate expandAsync and expandSync for the renamed corresponding me…
Browse files Browse the repository at this point in the history
…thods (#12914)
  • Loading branch information
alabiaga authored and William Chou committed Jan 25, 2018
1 parent 2270d9e commit 5fb3da2
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 188 deletions.
2 changes: 1 addition & 1 deletion builtins/amp-pixel.js
Expand Up @@ -88,7 +88,7 @@ export class AmpPixel extends BaseElement {
return;
}
return Services.urlReplacementsForDoc(this.element)
.expandAsync(this.assertSource_(src))
.expandUrlAsync(this.assertSource_(src))
.then(src => {
const pixel = this.referrerPolicy_
? createNoReferrerPixel(this.element, src)
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-access/0.1/amp-access.js
Expand Up @@ -416,7 +416,7 @@ export class AccessService {
*/
buildUrl(url, useAuthData) {
return this.prepareUrlVars_(useAuthData).then(vars => {
return this.urlReplacements_.expandAsync(url, vars);
return this.urlReplacements_.expandUrlAsync(url, vars);
});
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/amp-analytics.js
Expand Up @@ -443,7 +443,7 @@ export class AmpAnalytics extends AMP.BaseElement {
}
const ampdoc = this.getAmpDoc();
return Services.urlReplacementsForDoc(this.element)
.expandAsync(remoteConfigUrl)
.expandUrlAsync(remoteConfigUrl)
.then(expandedUrl => {
remoteConfigUrl = expandedUrl;
return Services.xhrFor(ampdoc.win).fetchJson(
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/requests.js
Expand Up @@ -120,7 +120,7 @@ export class RequestHandler {
this.baseUrlTemplatePromise_ =
this.variableService_.expandTemplate(this.baseUrl, expansionOption);
this.baseUrlPromise_ = this.baseUrlTemplatePromise_.then(baseUrl => {
return this.urlReplacementService_.expandAsync(
return this.urlReplacementService_.expandUrlAsync(
baseUrl, dynamicBindings, this.whiteList_);
});
};
Expand All @@ -131,7 +131,7 @@ export class RequestHandler {
// Construct the extraUrlParamsString: Remove null param and encode component
const expandedExtraUrlParamsStr =
this.getExtraUrlParamsString_(expandExtraUrlParams);
return this.urlReplacementService_.expandAsync(
return this.urlReplacementService_.expandUrlAsync(
expandedExtraUrlParamsStr, dynamicBindings, this.whiteList_);
});

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-call-tracking/0.1/amp-call-tracking.js
Expand Up @@ -82,7 +82,7 @@ export class AmpCallTracking extends AMP.BaseElement {
/** @override */
layoutCallback() {
return Services.urlReplacementsForDoc(this.getAmpDoc())
.expandAsync(user().assertString(this.configUrl_))
.expandUrlAsync(user().assertString(this.configUrl_))
.then(url => fetch_(this.win, url))
.then(data => {
user().assert('phoneNumber' in data,
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-social-share/0.1/amp-social-share.js
Expand Up @@ -102,7 +102,7 @@ class AmpSocialShare extends AMP.BaseElement {
});
}

urlReplacements.expandAsync(hrefWithVars, bindings).then(href => {
urlReplacements.expandUrlAsync(hrefWithVars, bindings).then(href => {
this.href_ = href;
// mailto:, whatsapp: protocols breaks when opened in _blank on iOS Safari
const protocol = parseUrl(href).protocol;
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/0.1/amp-story.js
Expand Up @@ -1158,7 +1158,7 @@ export class AmpStory extends AMP.BaseElement {
opts.requireAmpResponseSourceOrigin = false;

return Services.urlReplacementsForDoc(this.getAmpDoc())
.expandAsync(user().assertString(rawUrl))
.expandUrlAsync(user().assertString(rawUrl))
.then(url => Services.xhrFor(this.win).fetchJson(url, opts))
.then(response => {
user().assert(response.ok, 'Invalid HTTP response for bookend JSON');
Expand Down
Expand Up @@ -175,7 +175,7 @@ export class AmpUserNotification extends AMP.BaseElement {
*/
buildGetHref_(ampUserId) {
const showIfHref = dev().assertString(this.showIfHref_);
return this.urlReplacements_.expandAsync(showIfHref).then(href => {
return this.urlReplacements_.expandUrlAsync(showIfHref).then(href => {
const data = /** @type {!JsonObject} */({
'elementId': this.elementId_,
'ampUserId': ampUserId,
Expand Down
2 changes: 1 addition & 1 deletion src/anchor-click-interceptor.js
Expand Up @@ -60,7 +60,7 @@ function maybeExpandUrlParams(ampdoc, e) {
return e.pageY;
},
};
const newHref = Services.urlReplacementsForDoc(ampdoc).expandSync(
const newHref = Services.urlReplacementsForDoc(ampdoc).expandUrlSync(
hrefToExpand, vars, undefined, /* opt_whitelist */ {
// For now we only allow to replace the click location vars
// and nothing else.
Expand Down
29 changes: 15 additions & 14 deletions src/batched-json.js
Expand Up @@ -32,18 +32,19 @@ import {getValueForExpr} from './json';
*/
export function fetchBatchedJsonFor(ampdoc, element, opt_expr) {
const url = assertHttpsUrl(element.getAttribute('src'), element);
return Services.urlReplacementsForDoc(ampdoc).expandAsync(url).then(src => {
const opts = {};
if (element.hasAttribute('credentials')) {
opts.credentials = element.getAttribute('credentials');
} else {
opts.requireAmpResponseSourceOrigin = false;
}
return Services.batchedXhrFor(ampdoc.win).fetchJson(src, opts);
}).then(res => res.json()).then(data => {
if (data == null) {
throw new Error('Response is undefined.');
}
return getValueForExpr(data, opt_expr || '.');
});
return Services.urlReplacementsForDoc(ampdoc).expandUrlAsync(url)
.then(src => {
const opts = {};
if (element.hasAttribute('credentials')) {
opts.credentials = element.getAttribute('credentials');
} else {
opts.requireAmpResponseSourceOrigin = false;
}
return Services.batchedXhrFor(ampdoc.win).fetchJson(src, opts);
}).then(res => res.json()).then(data => {
if (data == null) {
throw new Error('Response is undefined.');
}
return getValueForExpr(data, opt_expr || '.');
});
}
38 changes: 2 additions & 36 deletions src/service/url-replacements-impl.js
Expand Up @@ -644,40 +644,6 @@ export class UrlReplacements {
this.expander_ = new Expander(this.variableSource_);
}

/**
* Synchronously expands the provided URL by replacing all known variables with
* their resolved values. Optional `opt_bindings` can be used to add new
* variables or override existing ones. Any async bindings are ignored.
*
* TODO(mkhatib, #6322): Deprecate and please use expandUrlSync or expandStringSync.
* @param {string} url
* @param {!Object<string, (ResolverReturnDef|!SyncResolverDef)>=} opt_bindings
* @param {!Object<string, ResolverReturnDef>=} opt_collectVars
* @param {!Object<string, boolean>=} opt_whiteList Optional white list of names
* that can be substituted.
* @return {string}
*/
expandSync(url, opt_bindings, opt_collectVars, opt_whiteList) {
return this.expandUrlSync(
url, opt_bindings, opt_collectVars, opt_whiteList);
}

/**
* Expands the provided URL by replacing all known variables with their
* resolved values. Optional `opt_bindings` can be used to add new variables
* or override existing ones.
*
* TODO(mkhatib, #6322): Deprecate and please use expandUrlAsync or expandStringAsync.
* @param {string} url
* @param {!Object<string, *>=} opt_bindings
* @param {!Object<string, boolean>=} opt_whiteList Optional white list of names
* that can be substituted.
* @return {!Promise<string>}
*/
expandAsync(url, opt_bindings, opt_whiteList) {
return this.expandUrlAsync(url, opt_bindings, opt_whiteList);
}


/**
* Synchronously expands the provided source by replacing all known variables with
Expand Down Expand Up @@ -905,7 +871,7 @@ export class UrlReplacements {
if (!whitelist || !whitelist['QUERY_PARAM']) {
// override whitelist and expand defaultUrlParams;
const overrideWhitelist = {'QUERY_PARAM': true};
defaultUrlParams = this.expandSync(
defaultUrlParams = this.expandUrlSync(
defaultUrlParams,
/* opt_bindings */ undefined,
/* opt_collectVars */ undefined,
Expand All @@ -915,7 +881,7 @@ export class UrlReplacements {
}

if (whitelist) {
href = this.expandSync(
href = this.expandUrlSync(
href,
/* opt_bindings */ undefined,
/* opt_collectVars */ undefined,
Expand Down

0 comments on commit 5fb3da2

Please sign in to comment.