Skip to content

Commit

Permalink
Merge pull request #3607 from kumarharsh/fix/debounce-leak
Browse files Browse the repository at this point in the history
fix(knobs): cancel debounced onChange on unmounting
  • Loading branch information
ndelangen authored May 19, 2018
2 parents b9c7c34 + e188459 commit b414338
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addons/knobs/src/components/types/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class ArrayType extends React.Component {
this.onChange = debounce(this.props.onChange, 200);
}

componentWillUnmount() {
this.onChange.cancel();
}

handleChange = e => {
const { knob } = this.props;
const { value } = e.target;
Expand Down
1 change: 1 addition & 0 deletions addons/knobs/src/components/types/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ColorType extends React.Component {
}
componentWillUnmount() {
document.removeEventListener('mousedown', this.handleWindowMouseDown);
this.onChange.cancel();
}

handleWindowMouseDown = e => {
Expand Down
4 changes: 4 additions & 0 deletions addons/knobs/src/components/types/Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class NumberType extends React.Component {
this.onChange = debounce(props.onChange, 400);
}

componentWillUnmount() {
this.onChange.cancel();
}

handleChange = event => {
const { value } = event.target;

Expand Down
4 changes: 4 additions & 0 deletions addons/knobs/src/components/types/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ObjectType extends React.Component {
this.onChange = debounce(props.onChange, 200);
}

componentWillUnmount() {
this.onChange.cancel();
}

handleChange = e => {
const { value } = e.target;

Expand Down
4 changes: 4 additions & 0 deletions addons/knobs/src/components/types/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class TextType extends React.Component {
this.onChange = debounce(props.onChange, 200);
}

componentWillUnmount() {
this.onChange.cancel();
}

handleChange = event => {
const { value } = event.target;

Expand Down

0 comments on commit b414338

Please sign in to comment.