Skip to content

Commit

Permalink
fix getDynamicStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
kof committed Apr 13, 2017
1 parent 7081337 commit b60654e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/utils/getDynamicStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* Extracts a styles object with only props that contain function values.
*/
export default (styles: Object): Object|null => {
let fnValuesCounter = 0

// eslint-disable-next-line no-shadow
function extract(styles: Object): Object {
let to
let to = null

for (const key in styles) {
const value = styles[key]
Expand All @@ -15,18 +13,18 @@ export default (styles: Object): Object|null => {
if (type === 'function') {
if (!to) to = {}
to[key] = value
fnValuesCounter++
}
else if (type === 'object' && value !== null && !Array.isArray(value)) {
if (!to) to = {}
const extracted = extract(value)
if (extracted) to[key] = extracted
if (extracted) {
if (!to) to = {}
to[key] = extracted
}
}
}

return to
}

const extracted = extract(styles)
return fnValuesCounter ? extracted : null
return extract(styles)
}
5 changes: 5 additions & 0 deletions tests/unit/getDynamicStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('Unit: jss - getDynamicStyles', () => {
width: 2,
color
}
},
nested: {
'& a': {
color: 'red'
}
}
}
expect(getDynamicStyles(styles)).to.eql({
Expand Down

0 comments on commit b60654e

Please sign in to comment.