Skip to content

Commit

Permalink
* dtable: fix dtable component with signal cause perf issue for sorti…
Browse files Browse the repository at this point in the history
…ng cols on dragging.
  • Loading branch information
catouse committed Oct 22, 2024
1 parent 3942d60 commit e8bd5c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
8 changes: 6 additions & 2 deletions lib/dtable/src/components/dtable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, createRef, h as _h} from 'preact';
import {classes, $, i18n, CustomContent, nextGid, CustomRender, dom} from '@zui/core';
import {classes, $, i18n, CustomContent, nextGid, CustomRender, dom, isShallowDiff} from '@zui/core';
import {Scrollbar} from '@zui/scrollbar/src/component/scrollbar';
import {addPlugin, initPlugins, removePlugin} from '../helpers/shared-plugins';
import {getDefaultOptions} from '../helpers/default-options';
Expand All @@ -9,7 +9,7 @@ import {Block} from './block';
import type {ComponentChildren, ErrorInfo} from 'preact';
import type {ClassNameLike, CustomRenderResult, CustomRenderResultList} from '@zui/core';
import type {CellProps, CellRenderCallback} from '../types/cell';
import type {ColInfoLike, ColInfo, ColName} from '../types/col';
import type {ColInfoLike, ColInfo, ColName, ColSetting} from '../types/col';
import type {DTableState, DTableLayout, DTableEventListener, DTableEventTarget, DTablePointerInfo} from '../types';
import type {DTableOptions} from '../types/options';
import type {DTablePlugin} from '../types/plugin';
Expand Down Expand Up @@ -116,6 +116,10 @@ export class DTable extends Component<DTableOptions, DTableState> {
this._options = undefined;
}

shouldComponentUpdate(nextProps: Readonly<DTableOptions<ColSetting>>, nextState: Readonly<DTableState>): boolean {
return isShallowDiff(this.state, nextState) || isShallowDiff(this.props, nextProps);
}

componentDidMount() {
if (this._needRender) {
this.forceUpdate();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dayjs": "^1.11.11",
"htm": "^3.1.1",
"nanoid": "^5.0.7",
"preact": "^10.23.2",
"preact": "^10.24.3",
"tinykeys": "^2.1.0"
},
"devDependencies": {
Expand Down
37 changes: 20 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8bd5c1

Please sign in to comment.