From 30f029e8598a7918c7bb6654bce5ba9339df4aee Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Thu, 6 Feb 2020 15:13:31 +0300 Subject: [PATCH] refactor(xod-client): get rid of recompose from ColorPinWidget due to optimization and tweak throttling --- .../pinWidgets/ColorPinWidget.jsx | 204 +++++++++--------- 1 file changed, 108 insertions(+), 96 deletions(-) diff --git a/packages/xod-client/src/editor/components/inspectorWidgets/pinWidgets/ColorPinWidget.jsx b/packages/xod-client/src/editor/components/inspectorWidgets/pinWidgets/ColorPinWidget.jsx index 307d00997..dd93f07b0 100644 --- a/packages/xod-client/src/editor/components/inspectorWidgets/pinWidgets/ColorPinWidget.jsx +++ b/packages/xod-client/src/editor/components/inspectorWidgets/pinWidgets/ColorPinWidget.jsx @@ -3,8 +3,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import { compose, withState, withHandlers, lifecycle } from 'recompose'; -import { debounce } from 'throttle-debounce'; +import { throttle } from 'throttle-debounce'; import { showColorPickerWidget, tweakNodeProperty } from '../../../actions'; import PinWidget from './PinWidget'; @@ -12,102 +11,113 @@ import { hex2color } from '../../ColorPicker'; import ColorPickerWidget from '../../../containers/ColorPickerWidget'; import { isSessionActive } from '../../../../debugger/selectors'; -const ColorPinWidget = compose( - withState('value', 'setValue', props => props.value), - withState('focused', 'setFocus', false), - // We have to handle input's selection in a tricky way, - // because we're changing it's value on focus - withState('selection', 'setSelection', [0, 0]), - withState('inputRef', 'setInputRef', null), - // We have to handle it in case we just added a leading quote - // before the literal - lifecycle({ - componentDidUpdate(prevProps) { - if (prevProps.selection !== this.props.selection && this.props.inputRef) { - this.props.inputRef.setSelectionRange( - this.props.selection[0], - this.props.selection[1] - ); - } - }, - }), - withHandlers({ - commit: ({ onChange }) => debounce(200, value => onChange(value)), - }), - withHandlers({ - onChangeHandler: ({ - entityId, - kind, - keyName, - isActiveSession, - tweakColor, - setValue, - commit, - }) => value => { - setValue(value); - commit(value); - if (isActiveSession) { - tweakColor(entityId, kind, keyName, value); - } - }, - }), - withHandlers({ - onInputChange: ({ onChangeHandler }) => event => - onChangeHandler(event.target.value), - onWidgetChange: ({ onChangeHandler }) => color => - onChangeHandler(color.hex), - onFocus: props => event => { - props.setSelection([ - event.target.selectionStart, - event.target.selectionEnd, - ]); - props.setFocus(true); - }, - onBlur: props => _ => { - props.setFocus(false); - props.setSelection([0, 0]); - props.onBlur(); - }, - }) -)(props => ( - - - -