Skip to content

Commit

Permalink
reselect mechanism reduce script time
Browse files Browse the repository at this point in the history
  • Loading branch information
Foveluy committed Feb 27, 2018
1 parent f154d97 commit f9d4616
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 697 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"@types/react": "^16.0.38",
"@types/react-dom": "^16.0.4",
"@types/reselect": "^2.2.0",
"babel-jest": "^22.2.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
Expand All @@ -60,6 +61,7 @@
"prop-types": "^15.5.10",
"react": "^16.3.0-alpha.1",
"react-dom": "^16.3.0-alpha.1",
"reselect": "^3.0.1",
"typescript-babel-jest": "^1.0.5"
}
}
}
30 changes: 15 additions & 15 deletions src/lib/dragact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,24 @@ export class Dragact extends React.Component<DragactProps, DragactState> {

const newLayout = layoutCheck(this.state.layout, layoutItem, layoutItem.UniqueKey, layoutItem.UniqueKey, 0);

const { compacted, mapLayout } = compactLayout(newLayout, layoutItem)
const { compacted, mapLayout } = compactLayout(newLayout, layoutItem, this.state.mapLayout)

this.setState({
layout: compacted,
wMoving: layoutItem.w,
hMoving: layoutItem.h,
mapLayout: mapLayout,
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1])
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight)
})
}

onResizeEnd = (layoutItem: GridItemEvent) => {
const { compacted, mapLayout } = compactLayout(this.state.layout, undefined)
const { compacted, mapLayout } = compactLayout(this.state.layout, undefined, this.state.mapLayout)
this.setState({
placeholderShow: false,
layout: compacted,
mapLayout: mapLayout,
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1])
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight)
})
this.props.onDragEnd && this.props.onDragEnd(layoutItem);
}
Expand Down Expand Up @@ -199,27 +199,27 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
const moving = GridY - this.state.GridYMoving;

const newLayout = layoutCheck(this.state.layout, layoutItem, UniqueKey, UniqueKey/*用户移动方块的key */, moving);
const { compacted, mapLayout } = compactLayout(newLayout, layoutItem);
const { compacted, mapLayout } = compactLayout(newLayout, layoutItem, this.state.mapLayout);

this.setState({
GridXMoving: layoutItem.GridX,
GridYMoving: layoutItem.GridY,
layout: compacted,
mapLayout: mapLayout,
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1])
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight)
})
this.props.onDrag && this.props.onDrag(layoutItem);
}

onDragEnd(layoutItem: GridItemEvent) {

const { compacted, mapLayout } = compactLayout(this.state.layout, undefined)
const { compacted, mapLayout } = compactLayout(this.state.layout, undefined, this.state.mapLayout)

this.setState({
placeholderShow: false,
layout: compacted,
mapLayout: mapLayout,
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1])
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight)
})

this.props.onDragEnd && this.props.onDragEnd(layoutItem);
Expand Down Expand Up @@ -261,9 +261,9 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
const newLayout = this.state.layout.filter((child) => {
if (child.key !== key) return child
})
const { compacted, mapLayout } = compactLayout(newLayout, undefined);
const { compacted, mapLayout } = compactLayout(newLayout, undefined, this.state.mapLayout);
this.setState({
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1]),
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight),
layout: compacted,
mapLayout
})
Expand All @@ -283,11 +283,11 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
const dataSet = { ...item.props['data-set'], isUserMove: false, key: item.key };
var newLayout = [...this.state.layout, dataSet]
newLayout = correctLayout(newLayout, this.props.col)
const { compacted, mapLayout } = compactLayout(newLayout, undefined);
console.log(mapLayout)
const { compacted, mapLayout } = compactLayout(newLayout, undefined, this.state.mapLayout);
// console.log(mapLayout)
// console.log(layout)
this.setState({
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1]),
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight),
layout: compacted,
mapLayout
})
Expand All @@ -299,11 +299,11 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
componentDidMount() {
setTimeout(() => {
let layout = correctLayout(this.state.layout, this.props.col)
const { compacted, mapLayout } = compactLayout(layout, undefined);
const { compacted, mapLayout } = compactLayout(layout, undefined, this.state.mapLayout);
this.setState({
layout: compacted,
mapLayout: mapLayout,
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1])
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight)
})
}, 1);
}
Expand Down
Loading

0 comments on commit f9d4616

Please sign in to comment.