rmc-picker
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -14,3 +14,8 @@ // export this package's api | ||
var _PickerItem = require('./PickerItem'); | ||
var _PickerItem2 = _interopRequireDefault(_PickerItem); | ||
_Picker2['default'].PickerItem = _PickerItem2['default']; | ||
exports['default'] = _Picker2['default']; | ||
module.exports = exports['default']; |
@@ -27,18 +27,6 @@ 'use strict'; | ||
// compare two object, props.data with nextProps.data | ||
// data: [{value: '1', name: '1x'}, {value: '2', name: '2x'}...] | ||
function isEqual(preData, data) { | ||
if (preData.length !== data.length) { | ||
return false; | ||
} | ||
var equal = data.every(function (item, index) { | ||
return item.value === preData[index].value && item.name === preData[index].name; | ||
}); | ||
if (!equal) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
// console.log(isEqual([{value: '1', name: '1x'}, {value: '2', name: '2x'}], [{value: '1', name: '1x'}])); | ||
var _PickerItem = require('./PickerItem'); | ||
var _PickerItem2 = _interopRequireDefault(_PickerItem); | ||
var Picker = _react2['default'].createClass({ | ||
@@ -49,3 +37,2 @@ displayName: 'Picker', | ||
prefixCls: _react2['default'].PropTypes.string, | ||
data: _react2['default'].PropTypes.array, | ||
onValueChange: _react2['default'].PropTypes.func, | ||
@@ -65,8 +52,2 @@ selectedValue: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.number]), | ||
}, | ||
shouldComponentUpdate: function shouldComponentUpdate(nextProps) { | ||
if (isEqual(this.props.data, nextProps.data) && this.iscroll) { | ||
return false; | ||
} | ||
return true; | ||
}, | ||
componentDidUpdate: function componentDidUpdate() { | ||
@@ -108,3 +89,3 @@ var _this = this; | ||
if (this.props.onValueChange && index !== undefined) { | ||
this.props.onValueChange(this.data[index]); | ||
this.props.onValueChange(this.userData[index]); | ||
} | ||
@@ -127,4 +108,2 @@ }, | ||
var data = [].concat(_toConsumableArray(props.data)); | ||
this.data = data; | ||
// 前后补三个空元素,页面展示需要 | ||
@@ -135,8 +114,15 @@ var temp = [0, 1, 2].map(function () { | ||
var len = temp.length; | ||
data = [].concat(_toConsumableArray(temp), _toConsumableArray(data), _toConsumableArray(temp)); | ||
this.userData = []; | ||
_react2['default'].Children.forEach(props.children, function (child) { | ||
if (child.type === _PickerItem2['default']) { | ||
_this3.userData.push({ value: child.props.value, name: child.props.name }); | ||
} | ||
}); | ||
var compositeData = [].concat(_toConsumableArray(temp), _toConsumableArray(this.userData), _toConsumableArray(temp)); | ||
// get default scroll position | ||
this.defaultScrollPosition = 0; | ||
if (props.selectedValue) { | ||
data.forEach(function (item, index) { | ||
compositeData.forEach(function (item, index) { | ||
if (item.value === props.selectedValue) { | ||
@@ -157,3 +143,3 @@ _this3.defaultScrollPosition = index - len; | ||
{ ref: 'iscroll_scroller', className: prefixCls + '-scroller' }, | ||
data.map(function (item, index) { | ||
compositeData.map(function (item, index) { | ||
return _react2['default'].createElement( | ||
@@ -160,0 +146,0 @@ 'div', |
{ | ||
"name": "rmc-picker", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "m-picker ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -59,3 +59,3 @@ # rmc-picker | ||
### props | ||
### Picker props | ||
@@ -66,7 +66,13 @@ | name | description | type | default | | ||
|prefixCls | prefix class | String | '' | | ||
|data | input data | array{obj} | [{name, value, selected(option)},...] | | ||
|selectedValue | default selected values corresponding to the input data above | string/number | | | ||
|onValueChange | fire when picker change | Function | '' | | ||
### PickerItem props | ||
| name | description | type | default | | ||
|----------|----------------|----------|--------------| | ||
|value | PickerItem value | any | '' | | ||
|name | PickerItem name | any | '' | | ||
## Test Case | ||
@@ -73,0 +79,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
87
0
11680
213