Skip to content

Commit

Permalink
fix: 添加 ts 类型给 compact, 并修复错误的 logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chuancey committed Mar 1, 2018
1 parent 8e97bfb commit 7ae8168
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/lib/dragact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {

resetLayout = () => {
const { compacted, mapLayout } = this.recalculateLayout(this.props.layout)
this.cachingLayout(this.state.mapLayout, this.state.layout);
this.cachingLayout();
this.storeLayoutToHistory();
this.setState({
layout: compacted,
Expand All @@ -181,7 +181,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
return;
}
this.activeItem = layoutItem
this.cachingLayout(this.state.mapLayout, this.state.layout);
this.cachingLayout();
}

cacheCurrentLayoutEnd = (layoutItem: GridItemEvent) => {
Expand All @@ -195,7 +195,8 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
this.storeLayoutToHistory()
}

cachingLayout = (mapLayout: mapLayout | undefined, layout: DragactLayoutItem[]) => {
cachingLayout = () => {
const { mapLayout, layout } = this.state
this.cacheLayouts = JSON.stringify({
mapLayout,
layout
Expand Down Expand Up @@ -374,7 +375,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
}

}

recalculateLayout = (layout: DragactLayoutItem[]) => {
layout = correctLayout(layout, this.props.col)
return compactLayout(layout, undefined, this.state.mapLayout);
Expand All @@ -383,11 +384,13 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
componentDidMount() {
setTimeout(() => {
const { compacted, mapLayout } = this.recalculateLayout(this.state.layout);
this.mapLayoutHistory.push(mapLayout);
this.setState({
layout: compacted,
mapLayout: mapLayout,
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight, false)
}, () => {
this.cachingLayout();
this.storeLayoutToHistory();
})
}, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const compactLayout = function () {
var _cache: any = {
};

return function (layout: DragactLayoutItem[], movingItem: GridItemEvent | undefined, mapedLayout: any) {
return function (layout: DragactLayoutItem[], movingItem: GridItemEvent | undefined, mapedLayout: mapLayout | undefined) {
if (movingItem) {
if (_cache.GridX === movingItem.GridX
&& _cache.GridY === movingItem.GridY &&
Expand Down

0 comments on commit 7ae8168

Please sign in to comment.