Skip to content

Commit

Permalink
Adding gaurds for .some() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephiescastle committed Sep 4, 2024
1 parent fcee7d3 commit de20ae3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
10 changes: 6 additions & 4 deletions packages/vue/src/components/NavDesktop/NavDesktop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ export default defineComponent({
// key into the breadcrumbs for each section
const sectionLinks = this.breadcrumb.menu_links[urlKey]
// check if any of the paths contained in the array are active
const isActive = sectionLinks.some((link: BreadcrumbPathObject) =>
mixinIsActivePath(link.path)
)
const isActive = sectionLinks?.length
? sectionLinks.some((link: BreadcrumbPathObject) => mixinIsActivePath(link.path))
: undefined
if (isActive) {
mixinUpdateGlobalChildren(sectionLinks)
}
Expand All @@ -265,7 +265,9 @@ export default defineComponent({
// get the more menu array
const arr = this.breadcrumb.more
// check if array contains current path
const isActive = arr.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
const isActive = arr?.length
? arr.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
: undefined
if (isActive) {
// clear the secondary nav store when visiting a breadcrumb page
// ensures blank secondary nav unless explicitly set via content page "Promote" settings
Expand Down
8 changes: 6 additions & 2 deletions packages/vue/src/components/NavDesktopEdu/NavDesktopEdu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ export default defineComponent({
// key into the breadcrumbs for each section
const objArray = this.breadcrumb.menu_links[urlKey]
// check if any of the paths contained in the array are active
const isActive = objArray.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
const isActive = objArray?.length
? objArray.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
: undefined
if (isActive) {
mixinUpdateGlobalChildren(this.breadcrumb.menu_links[urlKey])
}
Expand All @@ -267,7 +269,9 @@ export default defineComponent({
// get the more menu array
const arr = this.breadcrumb.more
// check if array contains current path
const isActive = arr.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
const isActive = arr?.length
? arr.some((el: BreadcrumbPathObject) => mixinIsActivePath(el.path))
: undefined
if (isActive) {
// clear the secondary nav store when visiting a breadcrumb page
// ensures blank secondary nav unless explicitly set via content page "Promote" settings
Expand Down
8 changes: 5 additions & 3 deletions packages/vue/src/components/NavMobile/NavMobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ export default defineComponent({
// key into the breadcrumbs for each section
const objArray = this.breadcrumb.menu_links[urlKey]
// check if any of the paths contained in the array are active
return objArray.some((el: BreadcrumbPathObject) => {
return mixinIsActivePath(el.path)
})
return objArray?.length
? objArray.some((el: BreadcrumbPathObject) => {
return mixinIsActivePath(el.path)
})
: undefined
}
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ export default defineComponent({
},
computed: {
hasContent() {
return this.contacts.some(
(c) => c.contact.name || c.contact.address || c.contact.phone || c.contact.email
)
return this.contacts?.length
? this.contacts.some(
(c) => c.contact.name || c.contact.address || c.contact.phone || c.contact.email
)
: undefined
}
},
methods: {
Expand Down
6 changes: 5 additions & 1 deletion packages/vue/src/templates/www/PageTimeline/PageTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ export default defineComponent({
},
created() {
const sortByParam = this.$route?.query.sortBy
if (sortByParam && sortByOptions.some((option) => option.value === sortByParam)) {
if (
sortByParam &&
sortByOptions &&
sortByOptions.some((option) => option.value === sortByParam)
) {
this.sortBy = sortByParam as SortBy
}
Expand Down
14 changes: 8 additions & 6 deletions packages/vue/src/utils/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,14 @@ export const mixinIsActivePath = (itemPath: string): Boolean => {
*/
export const mixinGetSrcSet = (srcSetObject: Partial<ImageObject>): string => {
let srcSet = ''
const valid = Object.keys(srcSetObject).some(function (key) {
if (key.startsWith('screen')) {
return true
}
return false
})
const valid = Object.keys(srcSetObject)?.length
? Object.keys(srcSetObject).some(function (key) {
if (key.startsWith('screen')) {
return true
}
return false
})
: false
if (valid) {
const srcSetArray: string[] = []
for (const [key, value] of Object.entries(srcSetObject)) {
Expand Down

0 comments on commit de20ae3

Please sign in to comment.