Skip to content

Commit

Permalink
Improve perf
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 26, 2015
1 parent d2dbf37 commit c41ba87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/_sortable-simple/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { configureDragDropContext, HTML5Backend } from 'react-dnd';
class Container extends Component {
constructor(props) {
super(props);

this.moveCard = this.moveCard.bind(this);

this.state = {
cards: [{
id: 1,
Expand Down Expand Up @@ -62,7 +65,7 @@ class Container extends Component {
<Card key={card.id}
id={card.id}
text={card.text}
moveCard={(id, afterId) => this.moveCard(id, afterId)} />
moveCard={this.moveCard} />
);
})}
</div>
Expand Down
9 changes: 9 additions & 0 deletions modules/configureDragDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const HANDLE_SEPARATOR = '🍣';

export default function configureDragDrop(InnerComponent, { getHandlers, getProps, managerName = 'dragDropManager' }) {
class DragDropContainer extends Component {
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(nextProps, this.props) ||
!shallowEqual(nextState, this.state);
}

constructor(props, context) {
super(props);

Expand All @@ -31,6 +36,10 @@ export default function configureDragDrop(InnerComponent, { getHandlers, getProp
}

componentWillReceiveProps(nextProps) {
if (shallowEqual(nextProps, this.props)) {
return;
}

const monitor = this.manager.getMonitor();

monitor.removeChangeListener(this.handleChange);
Expand Down

0 comments on commit c41ba87

Please sign in to comment.