Skip to content

Commit

Permalink
refactor widthhandler a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Jun 13, 2022
1 parent c61da03 commit 3f6b14d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ class Editor extends React.Component {
leading: true,
})

updateState = updates => this.setState(updates, () => this.onUpdate(this.state))
sync = () => this.onUpdate(this.state)

updateState = updates => this.setState(updates, this.sync)

updateCode = code => this.updateState({ code })
updateTitleBar = titleBar => this.updateState({ titleBar })
updateWidth = width => this.setState({ widthAdjustment: false, width })
confirmWidth = () => this.onUpdate(this.state)

getCarbonImage = async (
{
Expand Down Expand Up @@ -408,7 +409,7 @@ class Editor extends React.Component {
<WidthHandler
innerRef={this.carbonNode}
onChange={this.updateWidth}
onConfirm={this.confirmWidth}
onChangeComplete={this.sync}
paddingHorizontal={config.paddingHorizontal}
/>
}
Expand Down
6 changes: 3 additions & 3 deletions components/WidthHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function clamp(value, min, max) {
return value
}

export default function WidthHandler({ onChange, onConfirm, innerRef, paddingHorizontal }) {
export default function WidthHandler({ onChange, onChangeComplete, innerRef, paddingHorizontal }) {
const startX = React.useRef(null)
const startWidth = React.useRef(null)

Expand All @@ -35,11 +35,11 @@ export default function WidthHandler({ onChange, onConfirm, innerRef, paddingHor
React.useEffect(() => {
function handleMouseUp() {
startX.current = null
onConfirm()
onChangeComplete()
}
window.addEventListener('mouseup', handleMouseUp)
return () => window.removeEventListener('mouseup', handleMouseUp)
}, [onConfirm])
}, [onChangeComplete])

return (
// eslint-disable-next-line
Expand Down

0 comments on commit 3f6b14d

Please sign in to comment.