Skip to content

Commit

Permalink
Reinitialize on prop change
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosrocha committed Apr 24, 2015
1 parent 7d94cbc commit f6c39cc
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/DataMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ var containsIgnoreCase = function(a, b) {
return b.indexOf(a) >= 0;
};

function buildInitialState(props) {
return {
// Clone the initialData.
data: props.initialData.slice(0),
sortBy: props.initialSortBy,
filterValues: {},
currentPage: 0,
pageLength: props.initialPageLength
};
}

module.exports = {

getInitialState() {
return {
// Clone the initialData.
data: this.props.initialData.slice(0),
sortBy: this.props.initialSortBy,
filterValues: {},
currentPage: 0,
pageLength: this.props.initialPageLength
};
return buildInitialState(this.props);
},

getDefaultProps() {
Expand All @@ -33,6 +37,10 @@ module.exports = {
};
},

componentWillReceiveProps(nextProps) {
this.setState(buildInitialState(nextProps));
},

componentWillMount() {
// Do the initial sorting if specified.
var {sortBy, data} = this.state;
Expand Down

0 comments on commit f6c39cc

Please sign in to comment.