tinper-bee-core/lib/splitComponent.js

37 lines
1008 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
exports.__esModule = true;
var _entries = require("babel-runtime/core-js/object/entries");
var _entries2 = _interopRequireDefault(_entries);
exports.default = splitComponentProps;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* 分割要传入父元素和子元素的props
* @param {[object]} props 传入的属性
* @param {[reactElement]} Component 组件
* @return {[array]} 返回数组第一个元素为父元素props对象第二个子元素props对象
*/
function splitComponentProps(props, Component) {
var componentPropTypes = Component.propTypes;
var parentProps = {};
var childProps = {};
(0, _entries2.default)(props).forEach(function (_ref) {
var propName = _ref[0],
propValue = _ref[1];
if (componentPropTypes[propName]) {
parentProps[propName] = propValue;
} else {
childProps[propName] = propValue;
}
});
return [parentProps, childProps];
}