Skip to content

Commit

Permalink
Move onChange to BufferedResizable
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Mar 6, 2017
1 parent a78c438 commit bc956dc
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/components/resizable.js
Expand Up @@ -6,7 +6,7 @@ const { func, node, bool, number, oneOf } = PropTypes
const { Draggable } = require('./draggable')
const cx = require('classnames')
const { bounds } = require('../dom')
const { noop, restrict, titlecase } = require('../common/util')
const { noop, restrict, titlecase, refine } = require('../common/util')
const { keys } = Object


Expand Down Expand Up @@ -100,15 +100,9 @@ class Resizable extends PureComponent {
this.props.onResize(this.getNewValue(event), event, this)
}

handleDragStop = () => {
const { value, onResizeStop, onChange } = this.props

if (onResizeStop) {
onResizeStop(this.value, this)
}

if (value !== this.value && onChange) {
onChange(this.value, this)
handleDragStop = (event) => {
if (this.props.onResizeStop) {
this.props.onResizeStop(event, this)
}
}

Expand Down Expand Up @@ -150,7 +144,6 @@ class Resizable extends PureComponent {
value: number,
min: number.isRequired,
max: number,
onChange: func,
onResize: func.isRequired,
onResizeStart: func,
onResizeStop: func,
Expand All @@ -171,6 +164,14 @@ class BufferedResizable extends Resizable {
this.state = {
value: props.value
}

refine(this, 'handleDragStop', () => {
const { value, onChange } = this.props

if (value !== this.value && onChange) {
onChange(this.value, this)
}
})
}

componentWillReceiveProps(props) {
Expand All @@ -188,6 +189,11 @@ class BufferedResizable extends Resizable {
this.setState({ value })
}
}

static propTypes = {
...Resizable.propTypes,
onChange: func
}
}


Expand Down

0 comments on commit bc956dc

Please sign in to comment.