bemto-components
Advanced tools
Comparing version 2.0.3 to 2.1.0
## Bemto-components changelog | ||
### v2.1.0 (2018-03-30) | ||
- Added `calculatedProps` to allow props passed inside an object to an element to be calculated when given as functions. | ||
- Fixed some linking issues by deep clone. | ||
### v2.0.3 (2018-03-29) | ||
@@ -4,0 +9,0 @@ |
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const cloneDeep = require('lodash.clonedeep'); | ||
@@ -131,3 +132,3 @@ // The code below is a mess, I'm sorry. But it is a working mess at least! | ||
const collectOptions = function(tagString, additionalOptions) { | ||
const options = additionalOptions || typeof tagString === 'object' && tagString || {}; | ||
const options = cloneDeep(additionalOptions || typeof tagString === 'object' && tagString || {}); | ||
const parsedTagString = parseTagString(options.tagString || typeof tagString === 'string' && tagString || ''); | ||
@@ -379,13 +380,31 @@ options.type = (typeof tagString === 'function' && React.Component.isPrototypeOf(tagString)) ? 'wrapper' : 'block'; | ||
const myPropsProps = item.props || {}; | ||
const myPropsProps = cloneDeep(item.props) || {}; | ||
// Handle props as functions | ||
for (var key in myPropsProps) { | ||
if (typeof myPropsProps[key] === 'function') { | ||
myPropsProps[key] = { | ||
bemtoCalculated: myPropsProps[key] | ||
} | ||
} | ||
} | ||
if (elemProp && elemProp.props) { | ||
for (var key in elemProp.props) { | ||
myPropsProps[key] = elemProp.props[key]; | ||
if (elemProp.calculatedProps && typeof elemProp.props[key] === 'function') { | ||
myPropsProps[key] = { | ||
bemtoCalculated: elemProp.props[key] | ||
}; | ||
} else { | ||
myPropsProps[key] = elemProp.props[key]; | ||
} | ||
} | ||
} | ||
myPropsProps.key = index; | ||
if (index !== undefined) { | ||
myPropsProps.key = index; | ||
} | ||
// Collecting options from everywhere | ||
const optsItem = collectOptions(item.tagString || '', item); | ||
const optsElem = typeof elemProp === 'object' && collectOptions('', elemProp) || {}; | ||
const optsElem = typeof elemProp === 'object' && collectOptions('', cloneDeep(elemProp)) || {}; | ||
@@ -411,2 +430,3 @@ const elemOptions = Object.assign( | ||
acceptProps: item.acceptProps, | ||
calculatedProps: item.calculatedProps || (elemProp && elemProp.calculatedProps), | ||
parsedTagString: parsedTagString, | ||
@@ -413,0 +433,0 @@ modifiers: elemOptions.modifiers |
{ | ||
"name": "bemto-components", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Smart components for using parts of BEM methodology with React", | ||
@@ -29,3 +29,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"react": "16.1.1" | ||
"lodash.clonedeep": "^4.5.0", | ||
"react": "16.2.0" | ||
}, | ||
@@ -38,5 +39,5 @@ "devDependencies": { | ||
"react-docgen-annotation-resolver": "^1.0.0", | ||
"react-dom": "^16.1.1", | ||
"react-dom": "^16.2.0", | ||
"react-styleguidist": "6.0.33", | ||
"react-test-renderer": "16.1.1", | ||
"react-test-renderer": "16.2.0", | ||
"styled-components": "^3.1.6", | ||
@@ -43,0 +44,0 @@ "webpack": "^3.8.1" |
1173916
5960
2
+ Addedlodash.clonedeep@^4.5.0
+ Addedlodash.clonedeep@4.5.0(transitive)
+ Addedreact@16.2.0(transitive)
- Removedreact@16.1.1(transitive)
Updatedreact@16.2.0