Skip to content

Commit 62d1dc1

Browse files
committed
refactor: remove some lodash function
1 parent 19e3460 commit 62d1dc1

File tree

18 files changed

+65
-65
lines changed

18 files changed

+65
-65
lines changed

src/components/action-sheet/body/item/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import classNames from 'classnames'
2-
import _isFunction from 'lodash/isFunction'
32
import PropTypes, { InferProps } from 'prop-types'
43
import { AtActionSheetItemProps } from 'types/action-sheet'
54
import { View } from '@tarojs/components'
@@ -13,7 +12,7 @@ export default class AtActionSheetItem extends AtComponent<
1312
public static propTypes: InferProps<AtActionSheetItemProps>
1413

1514
private handleClick = (args: any): void => {
16-
if (_isFunction(this.props.onClick)) {
15+
if (typeof this.props.onClick === 'function') {
1716
this.props.onClick(args)
1817
}
1918
}

src/components/action-sheet/footer/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import classNames from 'classnames'
2-
import _isFunction from 'lodash/isFunction'
32
import PropTypes, { InferProps } from 'prop-types'
43
import { AtActionSheetFooterProps } from 'types/action-sheet'
54
import { View } from '@tarojs/components'
@@ -13,7 +12,7 @@ export default class AtActionSheetFooter extends AtComponent<
1312
public static propTypes: InferProps<AtActionSheetFooterProps>
1413

1514
private handleClick = (...args: any[]): void => {
16-
if (_isFunction(this.props.onClick)) {
15+
if (typeof this.props.onClick === 'function') {
1716
this.props.onClick(...args)
1817
}
1918
}

src/components/action-sheet/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import classNames from 'classnames'
2-
import _isFunction from 'lodash/isFunction'
32
import PropTypes, { InferProps } from 'prop-types'
43
import { AtActionSheetProps, AtActionSheetState } from 'types/action-sheet'
54
import { View } from '@tarojs/components'
@@ -38,13 +37,13 @@ export default class AtActionSheet extends AtComponent<
3837
}
3938

4039
private handleClose = (): void => {
41-
if (_isFunction(this.props.onClose)) {
40+
if (typeof this.props.onClose === 'function') {
4241
this.props.onClose()
4342
}
4443
}
4544

4645
private handleCancel = (): void => {
47-
if (_isFunction(this.props.onCancel)) {
46+
if (typeof this.props.onCancel === 'function') {
4847
return this.props.onCancel()
4948
}
5049
this.close()

src/components/badge/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import classNames from 'classnames'
2-
import isNaN from 'lodash/isNaN'
32
import PropTypes, { InferProps } from 'prop-types'
43
import { AtBadgeProps } from 'types/badge'
54
import { View } from '@tarojs/components'
@@ -21,7 +20,7 @@ export default class AtBadge extends AtComponent<AtBadgeProps> {
2120
): string | number {
2221
if (value === '' || value === null || value === undefined) return ''
2322
const numValue = +value
24-
if (isNaN(numValue)) {
23+
if (Number.isNaN(numValue)) {
2524
return value
2625
}
2726
return numValue > maxValue ? `${maxValue}+` : numValue

src/components/calendar/body/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
Calendar
1111
} from 'types/calendar'
1212
import { Swiper, SwiperItem, View } from '@tarojs/components'
13-
import { BaseEvent, ITouch, ITouchEvent } from '@tarojs/components/types/common'
13+
import {
14+
BaseEventOrig,
15+
ITouch,
16+
ITouchEvent
17+
} from '@tarojs/components/types/common'
1418
import Taro from '@tarojs/taro'
1519
import { delayQuerySelector } from '../../../common/utils'
1620
import generateCalendarGroup from '../common/helper'
@@ -220,7 +224,12 @@ export default class AtCalendarBody extends Taro.Component<
220224
}
221225

222226
@bind
223-
private handleChange(e: BaseEvent) {
227+
private handleChange(
228+
e: BaseEventOrig<{
229+
current: number
230+
source: string
231+
}>
232+
) {
224233
const { current, source } = e.detail
225234

226235
if (source === 'touch') {

src/components/calendar/index.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import bind from 'bind-decorator'
22
import classnames from 'classnames'
33
import dayjs, { Dayjs } from 'dayjs'
4-
import _isFunction from 'lodash/isFunction'
5-
import _isObject from 'lodash/isObject'
6-
import _pick from 'lodash/pick'
74
import {
85
AtCalendarDefaultProps,
96
AtCalendarProps,
@@ -12,7 +9,7 @@ import {
129
Calendar
1310
} from 'types/calendar'
1411
import { View } from '@tarojs/components'
15-
import { BaseEvent } from '@tarojs/components/types/common'
12+
import { BaseEventOrig } from '@tarojs/components/types/common'
1613
import Taro from '@tarojs/taro'
1714
import AtCalendarBody from './body/index'
1815
import AtCalendarController from './controller/index'
@@ -174,7 +171,7 @@ export default class AtCalendar extends Taro.Component<
174171
private triggerChangeDate(value: Dayjs) {
175172
const { format } = this.props
176173

177-
if (!_isFunction(this.props.onMonthChange)) return
174+
if (typeof this.props.onMonthChange !== 'function') return
178175

179176
this.props.onMonthChange(value.format(format))
180177
}
@@ -189,7 +186,7 @@ export default class AtCalendar extends Taro.Component<
189186
generateDate: _generateDate.valueOf()
190187
})
191188

192-
if (vectorCount && _isFunction(this.props.onMonthChange)) {
189+
if (vectorCount && typeof this.props.onMonthChange === 'function') {
193190
this.props.onMonthChange(_generateDate.format(format))
194191
}
195192
}
@@ -202,7 +199,7 @@ export default class AtCalendar extends Taro.Component<
202199

203200
this.setMonth(-1)
204201

205-
if (_isFunction(this.props.onClickPreMonth)) {
202+
if (typeof this.props.onClickPreMonth === 'function') {
206203
this.props.onClickPreMonth()
207204
}
208205
}
@@ -215,14 +212,14 @@ export default class AtCalendar extends Taro.Component<
215212

216213
this.setMonth(1)
217214

218-
if (_isFunction(this.props.onClickNextMonth)) {
215+
if (typeof this.props.onClickNextMonth === 'function') {
219216
this.props.onClickNextMonth()
220217
}
221218
}
222219

223220
// picker 选择时间改变时触发
224221
@bind
225-
handleSelectDate(e: BaseEvent & { detail: { value: string } }) {
222+
handleSelectDate(e: BaseEventOrig<{ value: string }>) {
226223
const { value } = e.detail
227224

228225
const _generateDate: Dayjs = dayjs(value)
@@ -257,14 +254,14 @@ export default class AtCalendar extends Taro.Component<
257254
this.handleSelectedDate()
258255
})
259256

260-
if (_isFunction(this.props.onDayClick)) {
257+
if (typeof this.props.onDayClick === 'function') {
261258
this.props.onDayClick({ value: item.value })
262259
}
263260
}
264261

265262
handleSelectedDate() {
266263
const selectDate = this.state.selectedDate
267-
if (_isFunction(this.props.onSelectDate)) {
264+
if (typeof this.props.onSelectDate === 'function') {
268265
const info: Calendar.SelectedDate = {
269266
start: dayjs(selectDate.start).format(this.props.format)
270267
}
@@ -281,7 +278,7 @@ export default class AtCalendar extends Taro.Component<
281278

282279
@bind
283280
handleDayLongClick(item: Calendar.Item) {
284-
if (_isFunction(this.props.onDayLongClick)) {
281+
if (typeof this.props.onDayLongClick === 'function') {
285282
this.props.onDayLongClick({ value: item.value })
286283
}
287284
}

src/components/calendar/ui/date-list/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import bind from 'bind-decorator'
22
import classnames from 'classnames'
3-
import _isFunction from 'lodash/isFunction'
43
import { Calendar } from 'types/calendar'
54
import { Text, View } from '@tarojs/components'
65
import Taro from '@tarojs/taro'
@@ -25,14 +24,14 @@ export default class AtCalendarList extends Taro.Component<Props> {
2524

2625
@bind
2726
handleClick(item) {
28-
if (_isFunction(this.props.onClick)) {
27+
if (typeof this.props.onClick === 'function') {
2928
this.props.onClick(item)
3029
}
3130
}
3231

3332
@bind
3433
handleLongClick(item) {
35-
if (_isFunction(this.props.onLongClick)) {
34+
if (typeof this.props.onLongClick === 'function') {
3635
this.props.onLongClick(item)
3736
}
3837
}

src/components/card/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import classNames from 'classnames'
2-
import _isFunction from 'lodash/isFunction'
32
import PropTypes, { InferProps } from 'prop-types'
43
import { AtCardProps } from 'types/card'
54
import { Image, Text, View } from '@tarojs/components'
@@ -11,7 +10,7 @@ export default class AtCard extends AtComponent<AtCardProps> {
1110
public static propTypes: InferProps<AtCardProps>
1211

1312
private handleClick = (args: any): void => {
14-
if (_isFunction(this.props.onClick)) {
13+
if (typeof this.props.onClick === 'function') {
1514
this.props.onClick(args)
1615
}
1716
}

src/components/fab/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@ import classNames from 'classnames'
22
import PropTypes, { InferProps } from 'prop-types'
33
import { AtFabProps } from 'types/fab'
44
import { View } from '@tarojs/components'
5+
import { CommonEvent } from '@tarojs/components/types/common'
56
import Taro from '@tarojs/taro'
67
import AtComponent from '../../common/component'
78

89
export default class AtFab extends AtComponent<AtFabProps> {
910
public static defaultProps: AtFabProps
1011
public static propTypes: InferProps<AtFabProps>
1112

12-
private onClick(): void {
13-
this.props.onClick && this.props.onClick(arguments as any)
13+
private onClick(e: CommonEvent): void {
14+
if (typeof this.props.onClick === 'function') {
15+
this.props.onClick(e)
16+
}
1417
}
1518

1619
public render(): JSX.Element {
17-
const { size, className } = this.props
20+
const { size, className, children } = this.props
1821

1922
const rootClass = classNames('at-fab', className, {
2023
[`at-fab--${size}`]: size
2124
})
2225

2326
return (
2427
<View className={rootClass} onClick={this.onClick.bind(this)}>
25-
{this.props.children}
28+
{children}
2629
</View>
2730
)
2831
}

src/components/float-layout/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import classNames from 'classnames'
2-
import _isFunction from 'lodash/isFunction'
32
import PropTypes, { InferProps } from 'prop-types'
43
import { AtFloatLayoutProps, AtFloatLayoutState } from 'types/float-layout'
54
import { ScrollView, Text, View } from '@tarojs/components'
@@ -39,7 +38,7 @@ export default class AtFloatLayout extends AtComponent<
3938
}
4039

4140
private handleClose = () => {
42-
if (_isFunction(this.props.onClose)) {
41+
if (typeof this.props.onClose === 'function') {
4342
// @ts-ignore // TODO: Fix typings
4443
this.props.onClose()
4544
}

0 commit comments

Comments
 (0)