From 8eab40c4f5636af2c989f97b85aba5929fa625bc Mon Sep 17 00:00:00 2001 From: xobotyi Date: Mon, 24 Dec 2018 10:14:24 +0300 Subject: [PATCH] Fix the #34 issue [2]; First approach was incorrect; ToDo: cover custom renderers with tests. --- dist/Thumb.js | 18 ++++++++++++------ dist/Track.js | 16 ++++++++++++---- src/Thumb.js | 12 ++++++++++-- src/Track.js | 12 ++++++++++-- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/dist/Thumb.js b/dist/Thumb.js index daaabb5..42503d3 100644 --- a/dist/Thumb.js +++ b/dist/Thumb.js @@ -13,10 +13,12 @@ var _Track = _interopRequireDefault(require("./Track")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } - function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } + function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } @@ -160,12 +162,16 @@ function (_React$Component) { props.className = "thumb " + (type === TYPE_X ? "thumbX" : "thumbY") + (className ? " " + className : ""); props.onMouseDown = this.handleDragStart; - props.ref = function (ref) { - typeof elementRef === "function" && elementRef(ref); - _this2.element = ref; + var ref = function ref(_ref) { + typeof elementRef === "function" && elementRef(_ref); + _this2.element = _ref; }; - return renderer ? renderer(props) : _react.default.createElement("div", props); + return renderer ? renderer(_objectSpread({}, props, { + elementRef: ref + })) : _react.default.createElement("div", _extends({}, props, { + ref: ref + })); } }]); diff --git a/dist/Track.js b/dist/Track.js index 4023f04..e6d050e 100644 --- a/dist/Track.js +++ b/dist/Track.js @@ -13,6 +13,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } + function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } @@ -84,12 +88,16 @@ function (_React$Component) { props.className = "track " + (type === TYPE_X ? "trackX" : "trackY") + (className ? " " + className : ""); props.onClick = this.onClickHandler; - props.ref = function (ref) { - typeof elementRef === "function" && elementRef(ref); - _this2.element = ref; + var ref = function ref(_ref) { + typeof elementRef === "function" && elementRef(_ref); + _this2.element = _ref; }; - return renderer ? renderer(props) : _react.default.createElement("div", props); + return renderer ? renderer(_objectSpread({}, props, { + elementRef: ref + })) : _react.default.createElement("div", _extends({}, props, { + ref: ref + })); } }]); diff --git a/src/Thumb.js b/src/Thumb.js index a9faa4b..76b3ba9 100644 --- a/src/Thumb.js +++ b/src/Thumb.js @@ -109,11 +109,19 @@ export default class Thumb extends React.Component { props.className = "thumb " + (type === TYPE_X ? "thumbX" : "thumbY") + (className ? " " + className : ""); props.onMouseDown = this.handleDragStart; - props.ref = ref => { + + const ref = ref => { typeof elementRef === "function" && elementRef(ref); this.element = ref; }; - return renderer ? renderer(props) :
; + return renderer ? ( + renderer({ + ...props, + elementRef: ref, + }) + ) : ( +
+ ); } } diff --git a/src/Track.js b/src/Track.js index 35a594f..bde43a1 100644 --- a/src/Track.js +++ b/src/Track.js @@ -39,11 +39,19 @@ export default class Track extends React.Component { props.className = "track " + (type === TYPE_X ? "trackX" : "trackY") + (className ? " " + className : ""); props.onClick = this.onClickHandler; - props.ref = ref => { + + const ref = ref => { typeof elementRef === "function" && elementRef(ref); this.element = ref; }; - return renderer ? renderer(props) :
; + return renderer ? ( + renderer({ + ...props, + elementRef: ref, + }) + ) : ( +
+ ); } }