From 380e4cd53dd893e142a19966fc7a0b19c69cb9f4 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 5 Jan 2019 11:24:25 +0800 Subject: [PATCH] perf: some code --- .../__tests__/__snapshots__/demo.test.js.snap | 2 +- .../__tests__/__snapshots__/demo.test.js.snap | 4 +- components/modal/Modal.jsx | 2 +- components/modal/confirm.js | 3 +- components/pagination/Pagination.jsx | 2 - .../__snapshots__/index.test.js.snap | 12 + components/progress/__tests__/index.test.js | 5 + components/spin/Spin.jsx | 20 +- .../__snapshots__/index.test.js.snap | 12 +- .../__snapshots__/Table.filter.test.js.snap | 64 ++-- .../Table.pagination.test.js.snap | 68 ++-- .../Table.rowSelection.test.js.snap | 173 +++++---- .../__snapshots__/Table.test.js.snap | 67 +++- .../__snapshots__/empty.test.js.snap | 337 +++++++++++++++--- components/vc-menu/MenuItem.jsx | 2 +- 15 files changed, 552 insertions(+), 221 deletions(-) diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index 7403a0621..cd35ad056 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -545,7 +545,7 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
-
+
ABCDEF
diff --git a/components/grid/__tests__/__snapshots__/demo.test.js.snap b/components/grid/__tests__/__snapshots__/demo.test.js.snap index ad2151b0f..8d1e35fce 100644 --- a/components/grid/__tests__/__snapshots__/demo.test.js.snap +++ b/components/grid/__tests__/__snapshots__/demo.test.js.snap @@ -160,7 +160,7 @@ exports[`renders ./components/grid/demo/playfround.md correctly 1`] = `
Gutter (px):
-
+
@@ -169,7 +169,7 @@ exports[`renders ./components/grid/demo/playfround.md correctly 1`] = `
Column Count:
-
+
diff --git a/components/modal/Modal.jsx b/components/modal/Modal.jsx index d79019a8c..5f9d12963 100644 --- a/components/modal/Modal.jsx +++ b/components/modal/Modal.jsx @@ -29,7 +29,7 @@ const modalProps = (defaultProps = {}) => { /** 点击模态框右上角叉、取消按钮、Props.maskClosable 值为 true 时的遮罩层或键盘按下 Esc 时的回调*/ // onCancel: (e: React.MouseEvent) => void, afterClose: PropTypes.func.def(noop), - /** 居中 */ + /** 垂直居中 */ centered: PropTypes.bool, /** 宽度*/ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), diff --git a/components/modal/confirm.js b/components/modal/confirm.js index df5f92bc2..796187269 100644 --- a/components/modal/confirm.js +++ b/components/modal/confirm.js @@ -26,8 +26,7 @@ export default function confirm (config) { confirmDialogInstance = null div.parentNode.removeChild(div) } - const triggerCancel = args && args.length && - args.some(param => param && param.triggerCancel) + const triggerCancel = args.some(param => param && param.triggerCancel) if (config.onCancel && triggerCancel) { config.onCancel(...args) } diff --git a/components/pagination/Pagination.jsx b/components/pagination/Pagination.jsx index 3f14d5863..f536fcab6 100644 --- a/components/pagination/Pagination.jsx +++ b/components/pagination/Pagination.jsx @@ -2,7 +2,6 @@ import PropTypes from '../_util/vue-types' import VcSelect from '../select' import MiniSelect from './MiniSelect' -import enUS from '../vc-pagination/locale/en_US' import LocaleReceiver from '../locale-provider/LocaleReceiver' import { getOptionProps } from '../_util/props-util' import VcPagination from '../vc-pagination' @@ -121,7 +120,6 @@ export default { return ( `; +exports[`Progress render normal progress 1`] = ` +
+
+
+
+
+
+
0% +
+
+`; + exports[`Progress render out-of-range progress 1`] = `
diff --git a/components/progress/__tests__/index.test.js b/components/progress/__tests__/index.test.js index 062b470ea..9237c7651 100644 --- a/components/progress/__tests__/index.test.js +++ b/components/progress/__tests__/index.test.js @@ -98,4 +98,9 @@ describe('Progress', () => { expect(wrapper.html()).toMatchSnapshot() }) }) + + it('render normal progress', () => { + const wrapper = mount(Progress, { propsData: { status: 'normal' }}) + expect(wrapper.html()).toMatchSnapshot() + }) }) diff --git a/components/spin/Spin.jsx b/components/spin/Spin.jsx index 11f042ce0..03326ec05 100644 --- a/components/spin/Spin.jsx +++ b/components/spin/Spin.jsx @@ -48,14 +48,6 @@ export default { } }, - mounted () { - this.$nextTick(() => { - const { spinning, delay } = this - if (shouldDelay(spinning, delay)) { - this.delayTimeout = window.setTimeout(this.delayUpdateSpinning, delay) - } - }) - }, updated () { this.$nextTick(() => { const { delay, spinning, sSpinning } = this @@ -150,26 +142,18 @@ export default { ) const children = this.getChildren() if (children) { - let animateClassName = prefixCls + '-nested-loading' - if (wrapperClassName) { - animateClassName += ' ' + wrapperClassName - } const containerClassName = { [`${prefixCls}-container`]: true, [`${prefixCls}-blur`]: sSpinning, } return ( - +
{sSpinning &&
{spinElement}
}
{children}
- +
) } return spinElement diff --git a/components/spin/__tests__/__snapshots__/index.test.js.snap b/components/spin/__tests__/__snapshots__/index.test.js.snap index d97d35e34..1504b5333 100644 --- a/components/spin/__tests__/__snapshots__/index.test.js.snap +++ b/components/spin/__tests__/__snapshots__/index.test.js.snap @@ -1,12 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Spin should only affect the spin element when set style to a nested xx 1`] = ` -
+
+
+
+
+
+
content
+
-
-
content
-
- `; exports[`Spin should render custom indicator when it's set 1`] = ` diff --git a/components/table/__tests__/__snapshots__/Table.filter.test.js.snap b/components/table/__tests__/__snapshots__/Table.filter.test.js.snap index d664d9c43..1635cec2f 100644 --- a/components/table/__tests__/__snapshots__/Table.filter.test.js.snap +++ b/components/table/__tests__/__snapshots__/Table.filter.test.js.snap @@ -11,27 +11,51 @@ exports[`Table.filter renders custom content correctly 1`] = ` `; exports[`Table.filter renders filter correctly 1`] = ` -
- - - - - - - - - - - -
Name
- Jack
- Lucy
- Tom
- Jerry
-
-
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
+
Name
+
+ Jack
+ Lucy
+ Tom
+ Jerry
+
+
+
+
+
-
`; exports[`Table.filter renders menu correctly 1`] = ` diff --git a/components/table/__tests__/__snapshots__/Table.pagination.test.js.snap b/components/table/__tests__/__snapshots__/Table.pagination.test.js.snap index 9bbc5140f..bdcf1ac1a 100644 --- a/components/table/__tests__/__snapshots__/Table.pagination.test.js.snap +++ b/components/table/__tests__/__snapshots__/Table.pagination.test.js.snap @@ -1,28 +1,50 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Table.pagination renders pagination correctly 1`] = ` -
- - - - - -
Name
- Jack
- Lucy
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + +
+
Name
+
+ Jack
+ Lucy
+
+
+
+ +
+
-
-
- -
`; diff --git a/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap b/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap index 52113f272..b28122afa 100644 --- a/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap +++ b/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap @@ -1,87 +1,106 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Table.rowSelection fix selection column on the left 1`] = ` -
- - - - - - - - - - - - - - - - - - - - - -
-
-
-
Name
-
- Jack
- Lucy
- Tom
- Jerry
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - -
-
-
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
Name
+
+ Jack
+ Lucy
+ Tom
+ Jerry
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
-
+
+
+
+
+
-
-
- -
`; exports[`Table.rowSelection render with default selection correctly 1`] = ` diff --git a/components/table/__tests__/__snapshots__/Table.test.js.snap b/components/table/__tests__/__snapshots__/Table.test.js.snap index 4317c5562..cdb6b69dd 100644 --- a/components/table/__tests__/__snapshots__/Table.test.js.snap +++ b/components/table/__tests__/__snapshots__/Table.test.js.snap @@ -1,21 +1,56 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Table renders JSX correctly 1`] = ` -
- - - - - - - - - -
Name
Age
First Name
Last Name
- JohnBrown32
- JimGreen42
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Name
+
+
Age
+
+
First Name
+
+
Last Name
+
+ JohnBrown32
+ JimGreen42
+
+
+
+
+
-
-
-
`; diff --git a/components/table/__tests__/__snapshots__/empty.test.js.snap b/components/table/__tests__/__snapshots__/empty.test.js.snap index 7ab1eee75..292428ad5 100644 --- a/components/table/__tests__/__snapshots__/empty.test.js.snap +++ b/components/table/__tests__/__snapshots__/empty.test.js.snap @@ -1,63 +1,294 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Table renders empty table 1`] = `
Column 1
Column 2
Column 3
Column 4
Column 5
Column 6
Column 7
Column 8
No data
`; +exports[`Table renders empty table 1`] = ` +
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
Column 1
+
+
Column 2
+
+
Column 3
+
+
Column 4
+
+
Column 5
+
+
Column 6
+
+
Column 7
+
+
Column 8
+
+
+
No data
+
+
+
+
+
+`; -exports[`Table renders empty table with custom emptyText 1`] = `
Column 1
Column 2
Column 3
Column 4
Column 5
Column 6
Column 7
Column 8
custom empty text
`; +exports[`Table renders empty table with custom emptyText 1`] = ` +
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
Column 1
+
+
Column 2
+
+
Column 3
+
+
Column 4
+
+
Column 5
+
+
Column 6
+
+
Column 7
+
+
Column 8
+
+
+
custom empty text
+
+
+
+
+
+`; -exports[`Table renders empty table with fixed columns 1`] = `
Full Name
Age
Column 1
Column 2
Column 3
Column 4
Column 5
Column 6
Column 7
Column 8
Action
No data
Full Name
Age
Action
`; +exports[`Table renders empty table with fixed columns 1`] = ` +
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Full Name
+
+
Age
+
+
Column 1
+
+
Column 2
+
+
Column 3
+
+
Column 4
+
+
Column 5
+
+
Column 6
+
+
Column 7
+
+
Column 8
+
+
Action
+
+
+
No data
+
+
+ +
+
+ + + + + + + + + + + + +
+
Full Name
+
+
Age
+
+
+
+
+
+ +
+
+ + + + + + + + + + +
+
Action
+
+
+
+
+
+
+
+
+
+`; exports[`Table renders empty table without emptyText when loading 1`] = ` -
-
-
-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - -
-
Column 1
-
-
Column 2
-
-
Column 3
-
-
Column 4
-
-
Column 5
-
-
Column 6
-
-
Column 7
-
-
Column 8
-
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
Column 1
+
+
Column 2
+
+
Column 3
+
+
Column 4
+
+
Column 5
+
+
Column 6
+
+
Column 7
+
+
Column 8
+
+
+
+
-
-
+
`; diff --git a/components/vc-menu/MenuItem.jsx b/components/vc-menu/MenuItem.jsx index 2e12d011c..459a772c7 100644 --- a/components/vc-menu/MenuItem.jsx +++ b/components/vc-menu/MenuItem.jsx @@ -14,7 +14,7 @@ const props = { active: PropTypes.bool, selectedKeys: PropTypes.array, disabled: PropTypes.bool, - title: PropTypes.string, + title: PropTypes.any, index: PropTypes.number, inlineIndent: PropTypes.number.def(24), level: PropTypes.number.def(1),