Skip to content

Commit

Permalink
update to make terser happy
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Oct 26, 2021
1 parent 9083f87 commit f2104e4
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions src/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,42 @@ import {
/** @typedef {!../extensions/amp-subscriptions/0.1/amp-subscriptions.SubscriptionService} */
export let SubscriptionService;

/**
* Returns the global instance of the `AmpDocService` service that can be
* used to resolve an ampdoc for any node: either in the single-doc or
* shadow-doc environment.
* @param {!Window} window
* @return {!./service/ampdoc-impl.AmpDocService}
*/
function ampdocServiceFor(window) {
return /** @type {!./service/ampdoc-impl.AmpDocService} */ (
getService(window, 'ampdoc')
);
}

/**
* Returns the AmpDoc for the specified context node.
* @param {!Node|!./service/ampdoc-impl.AmpDoc} nodeOrAmpDoc
* @return {!./service/ampdoc-impl.AmpDoc}
*/
function ampdoc(nodeOrAmpDoc) {
return getAmpdoc(nodeOrAmpDoc);
}

/**
* @param {!Window} window
* @return {!./service/extensions-impl.Extensions}
*/
function extensionsFor(window) {
return /** @type {!./service/extensions-impl.Extensions} */ (
getService(window, 'extensions')
);
}

/**
* Services used to be a class full of static methods.
* We modified this to an object because minifiers have better support for it.
* Note: `Services` may not self-references or else it will deopt.
*/
export const Services = {
/**
Expand Down Expand Up @@ -106,27 +139,8 @@ export const Services = {
);
},

/**
* Returns the global instance of the `AmpDocService` service that can be
* used to resolve an ampdoc for any node: either in the single-doc or
* shadow-doc environment.
* @param {!Window} window
* @return {!./service/ampdoc-impl.AmpDocService}
*/
ampdocServiceFor: (window) => {
return /** @type {!./service/ampdoc-impl.AmpDocService} */ (
getService(window, 'ampdoc')
);
},

/**
* Returns the AmpDoc for the specified context node.
* @param {!Node|!./service/ampdoc-impl.AmpDoc} nodeOrAmpDoc
* @return {!./service/ampdoc-impl.AmpDoc}
*/
ampdoc: (nodeOrAmpDoc) => {
return getAmpdoc(nodeOrAmpDoc);
},
ampdoc: (nodeOrAmpdoc) => ampdoc(nodeOrAmpdoc),
ampdocServiceFor: (win) => ampdocServiceFor(win),

/**
* @param {!Element|!ShadowRoot} element
Expand All @@ -137,7 +151,7 @@ export const Services = {
if (loadAnalytics) {
// Get Extensions service and force load analytics extension.
const ampdoc = getAmpdoc(element);
Services.extensionsFor(ampdoc.win)./*OK*/ installExtensionForDoc(
extensionsFor(ampdoc.win)./*OK*/ installExtensionForDoc(
ampdoc,
'amp-analytics'
);
Expand Down Expand Up @@ -263,15 +277,7 @@ export const Services = {
).get();
},

/**
* @param {!Window} window
* @return {!./service/extensions-impl.Extensions}
*/
extensionsFor: (window) => {
return /** @type {!./service/extensions-impl.Extensions} */ (
getService(window, 'extensions')
);
},
extensionsFor: (win) => extensionsFor(win),

/**
* Returns a service to register callbacks we wish to execute when an
Expand Down Expand Up @@ -615,8 +621,8 @@ export const Services = {
* TODO(dmanek): Add tests for this method.
*/
storageForTopLevelDoc: (elementOrAmpDoc) => {
const thisAmpdoc = Services.ampdoc(elementOrAmpDoc);
const ampdocService = Services.ampdocServiceFor(thisAmpdoc.win);
const thisAmpdoc = ampdoc(elementOrAmpDoc);
const ampdocService = ampdocServiceFor(thisAmpdoc.win);
const topAmpdoc = ampdocService.isSingleDoc()
? ampdocService.getSingleDoc()
: null;
Expand Down

0 comments on commit f2104e4

Please sign in to comment.