chore: prefer nullish coalescing (#7125)

This commit is contained in:
neverland 2020-09-07 20:36:49 +08:00 committed by GitHub
parent c7303786ae
commit 4ffa6ead1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 37 deletions

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, isDef } from '../utils';
import { createNamespace } from '../utils';
import { raf, doubleRaf } from '../utils/dom/raf';
// Mixins
@ -35,7 +35,7 @@ export default createComponent({
computed: {
currentName() {
return isDef(this.name) ? this.name : this.index;
return this.name ?? this.index;
},
expanded() {

View File

@ -1,4 +1,4 @@
import { createNamespace, isDef } from '../utils';
import { createNamespace } from '../utils';
import { route, routeProps } from '../utils/router';
import { ChildrenMixin } from '../mixins/relation';
import Info from '../info';
@ -28,7 +28,7 @@ export default createComponent({
genIcon() {
const slot = this.slots('icon');
const info = isDef(this.badge) ? this.badge : this.info;
const info = this.badge ?? this.info;
if (slot) {
return (

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, addUnit, isDef } from '../utils';
import { createNamespace, addUnit } from '../utils';
import { BORDER } from '../utils/constant';
import { route, routeProps } from '../utils/router';
@ -71,7 +71,7 @@ export default createComponent({
genIcon() {
const iconSlot = this.slots('icon');
const info = isDef(this.badge) ? this.badge : this.info;
const info = this.badge ?? this.info;
if (iconSlot) {
return (

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, addUnit, isDef } from '../utils';
import { createNamespace, addUnit } from '../utils';
import { inherit } from '../utils/functional';
// Components
@ -64,10 +64,7 @@ function Icon(
>
{slots.default && slots.default()}
{imageIcon && <img class={bem('image')} src={name} />}
<Info
dot={props.dot}
info={isDef(props.badge) ? props.badge : props.info}
/>
<Info dot={props.dot} info={props.badge ?? props.info} />
</props.tag>
);
}

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, isDef } from '../utils';
import { createNamespace } from '../utils';
import { preventDefault } from '../utils/dom/event';
import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant';
import { pickerProps, DEFAULT_ITEM_HEIGHT } from './shared';
@ -86,9 +86,7 @@ export default createComponent({
let cursor = { children: this.columns };
while (cursor && cursor.children) {
const defaultIndex = isDef(cursor.defaultIndex)
? cursor.defaultIndex
: +this.defaultIndex;
const defaultIndex = cursor.defaultIndex ?? +this.defaultIndex;
formatted.push({
values: cursor.children,
@ -328,9 +326,7 @@ export default createComponent({
allowHtml={this.allowHtml}
className={item.className}
itemHeight={this.itemPxHeight}
defaultIndex={
isDef(item.defaultIndex) ? item.defaultIndex : +this.defaultIndex
}
defaultIndex={item.defaultIndex ?? +this.defaultIndex}
swipeDuration={this.swipeDuration}
visibleItemCount={this.visibleItemCount}
initialOptions={item.values}

View File

@ -1,4 +1,4 @@
import { createNamespace, isDef, addUnit } from '../utils';
import { createNamespace, addUnit } from '../utils';
const [createComponent, bem] = createNamespace('progress');
@ -49,7 +49,7 @@ export default createComponent({
render() {
const { pivotText, percentage } = this;
const text = isDef(pivotText) ? pivotText : percentage + '%';
const text = pivotText ?? percentage + '%';
const showPivot = this.showPivot && text;
const background = this.inactive ? '#cacaca' : this.color;

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, isDef } from '../utils';
import { createNamespace } from '../utils';
// Mixins
import { popupMixinProps } from '../mixins/popup';
@ -112,7 +112,7 @@ export default createComponent({
},
genCancelText() {
const cancelText = isDef(this.cancelText) ? this.cancelText : t('cancel');
const cancelText = this.cancelText ?? t('cancel');
if (cancelText) {
return (

View File

@ -1,4 +1,4 @@
import { createNamespace, isDef } from '../utils';
import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation';
import { route, routeProps } from '../utils/router';
import Info from '../info';
@ -46,7 +46,7 @@ export default createComponent({
{this.title}
<Info
dot={this.dot}
info={isDef(this.badge) ? this.badge : this.info}
info={this.badge ?? this.info}
class={bem('info')}
/>
</div>

View File

@ -10,7 +10,7 @@ import SkuRowPropItem from './components/SkuRowPropItem';
import SkuStepper from './components/SkuStepper';
import SkuMessages from './components/SkuMessages';
import SkuActions from './components/SkuActions';
import { createNamespace, isDef } from '../utils';
import { createNamespace } from '../utils';
import {
isAllSelected,
isSkuChoosable,
@ -361,7 +361,7 @@ export default createComponent({
resetStepper() {
const { skuStepper } = this.$refs;
const { selectedNum } = this.initialSku;
const num = isDef(selectedNum) ? selectedNum : this.startSaleNum;
const num = selectedNum ?? this.startSaleNum;
// 用来缓存不合法的情况
this.stepperError = null;

View File

@ -72,7 +72,7 @@ export default createComponent({
},
data() {
const defaultValue = isDef(this.value) ? this.value : this.defaultValue;
const defaultValue = this.value ?? this.defaultValue;
const value = this.format(defaultValue);
if (!equal(value, this.value)) {

View File

@ -1,4 +1,4 @@
import { isDef, createNamespace } from '../utils';
import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation';
import { routeProps } from '../utils/router';
@ -26,7 +26,7 @@ export default createComponent({
computed: {
computedName() {
return isDef(this.name) ? this.name : this.index;
return this.name ?? this.index;
},
isActive() {

View File

@ -71,10 +71,7 @@ export default createComponent({
<div class={bem({ active })} style={{ color }} onClick={this.onClick}>
<div class={bem('icon')}>
{this.genIcon(active)}
<Info
dot={this.dot}
info={isDef(this.badge) ? this.badge : this.info}
/>
<Info dot={this.dot} info={this.badge ?? this.info} />
</div>
<div class={bem('text')}>{this.slots('default', { active })}</div>
</div>

View File

@ -359,7 +359,7 @@ export default createComponent({
refInFor
type={type}
dot={item.dot}
info={isDef(item.badge) ? item.badge : item.info}
info={item.badge ?? item.info}
title={item.title}
color={this.color}
style={item.titleStyle}

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, addUnit, isDef } from '../utils';
import { createNamespace, addUnit } from '../utils';
import { emit, inherit } from '../utils/functional';
// Components
@ -65,7 +65,7 @@ function TreeSelect(
const Navs = items.map((item) => (
<SidebarItem
dot={item.dot}
info={isDef(item.badge) ? item.badge : item.info}
info={item.badge ?? item.info}
title={item.text}
disabled={item.disabled}
class={[bem('nav-item'), item.className]}

View File

@ -30,7 +30,7 @@ export function get(object: any, path: string): any {
let result = object;
keys.forEach((key) => {
result = isDef(result[key]) ? result[key] : '';
result = result[key] ?? '';
});
return result;