Skip to content

Commit

Permalink
♻️ Use filter(Boolean) (#32997)
Browse files Browse the repository at this point in the history
Use a builtin instead of wrapping in function.
  • Loading branch information
alanorozco committed Mar 1, 2021
1 parent 6f4fe34 commit 710cf7c
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ads/vendors/fusion.js
Expand Up @@ -26,7 +26,7 @@ function queryParametersToObject(input) {
}
return input
.split('&')
.filter((_) => _)
.filter(Boolean)
.reduce((obj, val) => {
const kv = val.split('=');
return Object.assign(obj, {[kv[0]]: kv[1] || true});
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-ad-exit/0.1/amp-ad-exit.js
Expand Up @@ -375,7 +375,7 @@ export class AmpAdExit extends AMP.BaseElement {
vars: target['vars'] || {},
filters: (target['filters'] || [])
.map((f) => this.userFilters_[f])
.filter((f) => f),
.filter(Boolean),
behaviors: target['behaviors'] || {},
};
// Build a map of {vendor, origin} for 3p custom variables in the config
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/transport-serializer.js
Expand Up @@ -115,7 +115,7 @@ export const TransportSerializers = {
export function defaultSerializer(baseUrl, batchSegments) {
const extraUrlParamsStr = batchSegments
.map((item) => serializeQueryString(item['extraUrlParams']))
.filter((queryString) => !!queryString)
.filter(Boolean)
.join('&');
let requestUrl;
if (baseUrl.indexOf(EXTRA_URL_PARAM_VAR) >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-apester-media/0.1/utils.js
Expand Up @@ -124,7 +124,7 @@ export function extractArticleTags(ampdoc) {
return (ampdoc.getMetaByName('keywords') || '')
.split(',')
.map((e) => e.trim())
.filter((e) => e);
.filter(Boolean);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-auto-lightbox/0.1/amp-auto-lightbox.js
Expand Up @@ -341,7 +341,7 @@ export class DocMetaAnnotations {
const {textContent} = el;
return (tryParseJson(textContent) || {})['@type'];
})
.filter((typeOrUndefined) => typeOrUndefined);
.filter(Boolean);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-base-carousel/0.1/responsive-attributes.js
Expand Up @@ -50,7 +50,7 @@ function getMediaQueryListsAndValues(value) {
})
// Remove any items that did not match the regex above and are
// undefined as a result.
.filter((item) => item)
.filter(Boolean)
);
}

Expand Down
Expand Up @@ -62,7 +62,7 @@ describes.realWin(
const wrappers = await getSlideWrappersFromShadow();
const slots = Array.from(wrappers)
.map((wrapper) => wrapper.querySelector('slot'))
.filter((slot) => !!slot);
.filter(Boolean);
return toArray(slots).reduce(
(acc, slot) => acc.concat(slot.assignedElements()),
[]
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/amp-story-access.js
Expand Up @@ -327,7 +327,7 @@ export class AmpStoryAccess extends AMP.BaseElement {
* @private
*/
getActionObject_(namespace = undefined, type = undefined) {
const method = ['login', namespace, type].filter((s) => !!s).join('-');
const method = ['login', namespace, type].filter(Boolean).join('-');
return {tagOrTarget: 'SCRIPT', method};
}
}
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/amp-story.js
Expand Up @@ -1139,7 +1139,7 @@ export class AmpStory extends AMP.BaseElement {

const storyLoadPromise = Promise.all(
pagesToWaitFor
.filter((page) => !!page)
.filter(Boolean)
.map((page) =>
page.element.signals().whenSignal(CommonSignals.LOAD_END)
)
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/animation.js
Expand Up @@ -658,7 +658,7 @@ export class AnimationManager {
})
)
)
.filter((presetOrNull) => !!presetOrNull);
.filter(Boolean);
}
return devAssert(this.runners_);
}
Expand Down
Expand Up @@ -100,7 +100,7 @@ describes.realWin(
const wrappers = await getSlideWrappersFromShadow();
const slots = Array.from(wrappers)
.map((wrapper) => wrapper.querySelector('slot'))
.filter((slot) => !!slot);
.filter(Boolean);
return toArray(slots).reduce(
(acc, slot) => acc.concat(slot.assignedElements()),
[]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/media-query-props.js
Expand Up @@ -224,7 +224,7 @@ function parseMediaQueryListExpr(win, exprString) {
})
// Remove any items that did not match the regex above and are
// undefined as a result.
.filter((item) => item)
.filter(Boolean)
);
}

Expand Down

0 comments on commit 710cf7c

Please sign in to comment.