🌐 AI搜索 & 代理 主页
Skip to content

Commit ee1c10e

Browse files
authored
chore: code optimizations (#4418)
1 parent b02f93d commit ee1c10e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+472
-280
lines changed

src/components/alert/alert.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from '../../utils/vue'
22
import { getComponentConfig } from '../../utils/config'
33
import { requestAF } from '../../utils/dom'
44
import { isBoolean } from '../../utils/inspect'
5+
import { toInteger } from '../../utils/number'
56
import BVTransition from '../../utils/bv-transition'
67
import normalizeSlotMixin from '../../mixins/normalize-slot'
78
import { BButtonClose } from '../button/button-close'
@@ -13,7 +14,7 @@ const parseCountDown = show => {
1314
if (show === '' || isBoolean(show)) {
1415
return 0
1516
}
16-
show = parseInt(show, 10)
17+
show = toInteger(show)
1718
return show > 0 ? show : 0
1819
}
1920

@@ -22,15 +23,15 @@ const parseShow = show => {
2223
if (show === '' || show === true) {
2324
return true
2425
}
25-
if (parseInt(show, 10) < 1) {
26+
if (toInteger(show) < 1) {
2627
// Boolean will always return false for the above comparison
2728
return false
2829
}
29-
return Boolean(show)
30+
return !!show
3031
}
3132

3233
// Is a value number like (i.e. a number or a number as string)
33-
const isNumericLike = value => !isNaN(parseInt(value, 10))
34+
const isNumericLike = value => !isNaN(toInteger(value))
3435

3536
// @vue/component
3637
export const BAlert = /*#__PURE__*/ Vue.extend({

src/components/badge/badge.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ export const BBadge = /*#__PURE__*/ Vue.extend({
3232
functional: true,
3333
props,
3434
render(h, { props, data, children }) {
35-
const tag = !props.href && !props.to ? props.tag : BLink
35+
const isBLink = props.href || props.to
36+
const tag = isBLink ? BLink : props.tag
3637

3738
const componentData = {
3839
staticClass: 'badge',
3940
class: [
4041
props.variant ? `badge-${props.variant}` : 'badge-secondary',
4142
{
42-
'badge-pill': Boolean(props.pill),
43+
'badge-pill': props.pill,
4344
active: props.active,
4445
disabled: props.disabled
4546
}
4647
],
47-
props: pluckProps(linkProps, props)
48+
props: isBLink ? pluckProps(linkProps, props) : {}
4849
}
4950

5051
return h(tag, mergeData(data, componentData), children)

src/components/breadcrumb/breadcrumb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from '../../utils/vue'
22
import { mergeData } from 'vue-functional-data-merge'
3-
import toString from '../../utils/to-string'
43
import { isArray, isObject } from '../../utils/inspect'
4+
import { toString } from '../../utils/string'
55
import { BBreadcrumbItem } from './breadcrumb-item'
66

77
export const props = {

src/components/button-group/button-group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const BButtonGroup = /*#__PURE__*/ Vue.extend({
3535
class: {
3636
'btn-group': !props.vertical,
3737
'btn-group-vertical': props.vertical,
38-
[`btn-group-${props.size}`]: Boolean(props.size)
38+
[`btn-group-${props.size}`]: props.size
3939
},
4040
attrs: { role: props.ariaRole }
4141
}),

src/components/button/button.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getComponentConfig } from '../../utils/config'
66
import { addClass, removeClass } from '../../utils/dom'
77
import { isBoolean, isEvent, isFunction } from '../../utils/inspect'
88
import { keys } from '../../utils/object'
9+
import { toString } from '../../utils/string'
910
import { BLink, propsFactory as linkPropsFactory } from '../link/link'
1011

1112
// --- Constants --
@@ -62,6 +63,9 @@ export const props = { ...linkProps, ...btnProps }
6263

6364
// --- Helper methods ---
6465

66+
// Returns true if a tag's name is name
67+
const tagIs = (tag, name) => toString(tag).toLowerCase() === toString(name).toLowerCase()
68+
6569
// Focus handler for toggle buttons. Needs class of 'focus' when focused.
6670
const handleFocus = evt => {
6771
if (evt.type === 'focusin') {
@@ -72,23 +76,14 @@ const handleFocus = evt => {
7276
}
7377

7478
// Is the requested button a link?
75-
const isLink = props => {
76-
// If tag prop is set to `a`, we use a b-link to get proper disabled handling
77-
return Boolean(props.href || props.to || (props.tag && String(props.tag).toLowerCase() === 'a'))
78-
}
79+
// If tag prop is set to `a`, we use a b-link to get proper disabled handling
80+
const isLink = props => props.href || props.to || tagIs(props.tag, 'a')
7981

8082
// Is the button to be a toggle button?
8183
const isToggle = props => isBoolean(props.pressed)
8284

8385
// Is the button "really" a button?
84-
const isButton = props => {
85-
if (isLink(props)) {
86-
return false
87-
} else if (props.tag && String(props.tag).toLowerCase() !== 'button') {
88-
return false
89-
}
90-
return true
91-
}
86+
const isButton = props => !(isLink(props) || (props.tag && !tagIs(props.tag, 'button')))
9287

9388
// Is the requested tag not a button or link?
9489
const isNonStandardTag = props => !isLink(props) && !isButton(props)
@@ -97,7 +92,7 @@ const isNonStandardTag = props => !isLink(props) && !isButton(props)
9792
const computeClass = props => [
9893
`btn-${props.variant || getComponentConfig(NAME, 'variant')}`,
9994
{
100-
[`btn-${props.size}`]: Boolean(props.size),
95+
[`btn-${props.size}`]: props.size,
10196
'btn-block': props.block,
10297
'rounded-pill': props.pill,
10398
'rounded-0': props.squared && !props.pill,

src/components/card/card-body.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export const BCardBody = /*#__PURE__*/ Vue.extend({
5050
class: [
5151
{
5252
'card-img-overlay': props.overlay,
53-
[`bg-${props.bodyBgVariant}`]: Boolean(props.bodyBgVariant),
54-
[`border-${props.bodyBorderVariant}`]: Boolean(props.bodyBorderVariant),
55-
[`text-${props.bodyTextVariant}`]: Boolean(props.bodyTextVariant)
53+
[`bg-${props.bodyBgVariant}`]: props.bodyBgVariant,
54+
[`border-${props.bodyBorderVariant}`]: props.bodyBorderVariant,
55+
[`text-${props.bodyTextVariant}`]: props.bodyTextVariant
5656
},
5757
props.bodyClass || {}
5858
]

src/components/card/card-footer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export const BCardFooter = /*#__PURE__*/ Vue.extend({
3535
class: [
3636
props.footerClass,
3737
{
38-
[`bg-${props.footerBgVariant}`]: Boolean(props.footerBgVariant),
39-
[`border-${props.footerBorderVariant}`]: Boolean(props.footerBorderVariant),
40-
[`text-${props.footerTextVariant}`]: Boolean(props.footerTextVariant)
38+
[`bg-${props.footerBgVariant}`]: props.footerBgVariant,
39+
[`border-${props.footerBorderVariant}`]: props.footerBorderVariant,
40+
[`text-${props.footerTextVariant}`]: props.footerTextVariant
4141
}
4242
]
4343
}),

src/components/card/card-group.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ export const BCardGroup = /*#__PURE__*/ Vue.extend({
2222
functional: true,
2323
props,
2424
render(h, { props, data, children }) {
25-
let baseClass = 'card-group'
26-
if (props.deck) {
27-
baseClass = 'card-deck'
28-
} else if (props.columns) {
29-
baseClass = 'card-columns'
30-
}
31-
32-
return h(props.tag, mergeData(data, { class: baseClass }), children)
25+
return h(
26+
props.tag,
27+
mergeData(data, {
28+
class: props.deck ? 'card-deck' : props.columns ? 'card-columns' : 'card-group'
29+
}),
30+
children
31+
)
3332
}
3433
})

src/components/card/card-header.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export const BCardHeader = /*#__PURE__*/ Vue.extend({
3434
class: [
3535
props.headerClass,
3636
{
37-
[`bg-${props.headerBgVariant}`]: Boolean(props.headerBgVariant),
38-
[`border-${props.headerBorderVariant}`]: Boolean(props.headerBorderVariant),
39-
[`text-${props.headerTextVariant}`]: Boolean(props.headerTextVariant)
37+
[`bg-${props.headerBgVariant}`]: props.headerBgVariant,
38+
[`border-${props.headerBorderVariant}`]: props.headerBorderVariant,
39+
[`text-${props.headerTextVariant}`]: props.headerTextVariant
4040
}
4141
]
4242
}),

src/components/card/card.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export const BCard = /*#__PURE__*/ Vue.extend({
9090
'flex-row': props.imgLeft || props.imgStart,
9191
'flex-row-reverse':
9292
(props.imgRight || props.imgEnd) && !(props.imgLeft || props.imgStart),
93-
[`text-${props.align}`]: Boolean(props.align),
94-
[`bg-${props.bgVariant}`]: Boolean(props.bgVariant),
95-
[`border-${props.borderVariant}`]: Boolean(props.borderVariant),
96-
[`text-${props.textVariant}`]: Boolean(props.textVariant)
93+
[`text-${props.align}`]: props.align,
94+
[`bg-${props.bgVariant}`]: props.bgVariant,
95+
[`border-${props.borderVariant}`]: props.borderVariant,
96+
[`text-${props.textVariant}`]: props.textVariant
9797
}
9898
}),
9999
[imgFirst, header, ...content, footer, imgLast]

0 commit comments

Comments
 (0)