From be96fa2233f6af48616164d31117fbfa9ff7b808 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 8 Jul 2019 16:18:19 +0800 Subject: [PATCH] [improvement] make props less magic (#3775) --- src/action-sheet/index.tsx | 9 +-- src/address-edit/index.js | 4 +- src/address-list/index.tsx | 23 +++--- src/area/index.js | 2 +- src/cell/shared.ts | 6 +- src/checkbox-group/index.js | 7 +- src/circle/index.js | 10 ++- src/collapse-item/index.js | 2 +- src/contact-list/index.tsx | 76 +++++++++++-------- src/coupon-cell/index.tsx | 5 +- src/coupon-list/index.js | 10 ++- src/datetime-picker/index.js | 10 ++- src/dropdown-item/index.js | 7 +- src/field/index.js | 6 +- src/goods-action-icon/index.tsx | 2 +- src/grid/index.js | 2 +- src/icon/index.tsx | 4 +- src/image-preview/ImagePreview.js | 12 ++- src/image/index.js | 4 +- src/index-anchor/index.js | 2 +- src/info/index.tsx | 2 +- src/loading/index.tsx | 4 +- src/mixins/checkbox.js | 2 +- src/mixins/popup/index.js | 2 +- src/notice-bar/index.js | 2 +- src/notify/Notify.tsx | 2 +- src/number-keyboard/Key.js | 7 +- src/overlay/index.tsx | 5 +- src/pagination/index.js | 15 +++- src/password-input/index.tsx | 2 +- src/picker/PickerColumn.js | 7 +- src/picker/index.js | 10 ++- .../test/__snapshots__/index.spec.js.snap | 4 +- src/picker/test/index.spec.js | 3 +- src/popup/index.js | 5 +- src/rate/index.tsx | 9 ++- src/sidebar-item/index.js | 2 +- src/skeleton/index.tsx | 5 +- src/sku/Sku.js | 16 ++-- src/sku/components/SkuRowItem.js | 7 +- src/sku/components/SkuStepper.js | 14 +++- src/slider/index.js | 10 ++- src/stepper/index.js | 12 +-- src/steps/index.js | 5 +- src/submit-bar/index.tsx | 7 +- src/swipe-cell/index.js | 2 +- src/swipe/index.js | 21 ++--- src/tab/index.js | 2 +- src/tabbar-item/index.js | 6 +- src/tabbar/index.js | 2 +- src/tabs/index.js | 29 +++---- src/toast/Toast.js | 2 +- src/tree-select/index.tsx | 18 +++-- src/uploader/index.js | 21 ++--- src/utils/create/component.ts | 24 ------ 55 files changed, 283 insertions(+), 206 deletions(-) diff --git a/src/action-sheet/index.tsx b/src/action-sheet/index.tsx index f8846fe6c..cd64dba6f 100644 --- a/src/action-sheet/index.tsx +++ b/src/action-sheet/index.tsx @@ -21,7 +21,7 @@ export type ActionSheetItem = { export type ActionSheetProps = PopupMixinProps & { title?: string; - actions: ActionSheetItem[]; + actions?: ActionSheetItem[]; duration: number; cancelText?: string; closeOnClickAction?: boolean; @@ -126,7 +126,7 @@ function ActionSheet( {...inherit(ctx, true)} > {Header()} - {props.actions.map(Option)} + {props.actions && props.actions.map(Option)} {Content()} {CancelText()} @@ -137,14 +137,11 @@ ActionSheet.props = { ...PopupMixin.props, title: String, actions: Array, + duration: Number, cancelText: String, getContainer: [String, Function], closeOnClickAction: Boolean, safeAreaInsetBottom: Boolean, - duration: { - type: Number, - default: null - }, overlay: { type: Boolean, default: true diff --git a/src/address-edit/index.js b/src/address-edit/index.js index f1a0660f8..5b006ba7b 100644 --- a/src/address-edit/index.js +++ b/src/address-edit/index.js @@ -226,11 +226,11 @@ export default createComponent({ }, render(h) { - const { data, errorInfo } = this; + const { data, errorInfo, searchResult } = this; const onFocus = name => () => this.onFocus(name); // hide bottom field when use search && detail get focused - const hideBottomFields = this.searchResult.length && this.detailFocused; + const hideBottomFields = searchResult && searchResult.length && this.detailFocused; return (
diff --git a/src/address-list/index.tsx b/src/address-list/index.tsx index 987688811..bd8e75210 100644 --- a/src/address-list/index.tsx +++ b/src/address-list/index.tsx @@ -13,8 +13,8 @@ export type AddressListProps = { switchable: boolean; disabledText?: string; addButtonText?: string; - list: AddressItemData[]; - disabledList: AddressItemData[]; + list?: AddressItemData[]; + disabledList?: AddressItemData[]; }; export type AddressListSlots = DefaultSlots & { @@ -29,8 +29,12 @@ function AddressList( slots: AddressListSlots, ctx: RenderContext ) { - const getList = (list: AddressItemData[], disabled?: boolean) => - list.map((item, index) => ( + function renderList(list?: AddressItemData[], disabled?: boolean) { + if (!list) { + return; + } + + return list.map((item, index) => ( )); + } - const List = getList(props.list); - const DisabledList = getList(props.disabledList, true); + const List = renderList(props.list); + const DisabledList = renderList(props.disabledList, true); return (
@@ -59,9 +64,7 @@ function AddressList( > {List} - {props.disabledText && ( -
{props.disabledText}
- )} + {props.disabledText &&
{props.disabledText}
} {DisabledList} {slots.default && slots.default()}