Skip to content

Commit

Permalink
♻️ Restore array as prop value in createRule
Browse files Browse the repository at this point in the history
  • Loading branch information
exah committed Mar 7, 2019
1 parent 46c910e commit 2ea8967
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/core/create-rule.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isBool, isNum, isFn, identity, isStr, mapObj, isObj } from '@exah/utils'
import { isBool, isNum, isFn, identity, isStr, mapObj, isObj, toArr } from '@exah/utils'
import { wrap, wrapIfMedia, getThemeMedia } from '../utils'

const has = (a, b) => b.some((key) => a.includes(key))

function everyMedia (props, value, wrapper = identity) {
function everyMedia (props, value, wrapper) {
const media = getThemeMedia(props)

if (isObj(value) && has(Object.keys(media), Object.keys(value))) {
Expand Down Expand Up @@ -60,11 +60,14 @@ function createRule ({
return isFn(result) ? getValues(result, input, props, mediaKey) : result
}

return (input, props, mediaKey) => everyMedia(
props,
getValues(getValue, input, props, mediaKey),
(result) => getStyle(result, input, props, mediaKey)
)
return (inputs, props, mediaKey) => toArr(inputs).reduce((acc, input) => ({
...acc,
...everyMedia(
props,
getValues(getValue, input, props, mediaKey),
(result) => getStyle(result, input, props, mediaKey)
)
}), {})
}

export {
Expand Down
6 changes: 3 additions & 3 deletions src/styles/__tests__/box-style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { boxStyle, cs } from '../..'
import { boxStyle } from '../..'
import { toStyles } from '../../../test-helpers'

const theme = {
Expand Down Expand Up @@ -36,7 +36,7 @@ test('default', () => {
test('red, shadow', () => {
const result = toStyles(boxStyle({
theme,
boxStyle: cs('red', 'shadow')
boxStyle: [ 'red', 'shadow' ]
}))

expect(result).toEqual({
Expand All @@ -49,7 +49,7 @@ test('red, shadow', () => {
test('variant', () => {
const result = toStyles(boxStyle.variant({
theme,
variant: cs('red', 'shadow')
variant: [ 'red', 'shadow' ]
}))

expect(result).toEqual({
Expand Down
6 changes: 3 additions & 3 deletions src/styles/__tests__/text-style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { textStyle, cs } from '../..'
import { textStyle } from '../..'
import { toStyles } from '../../../test-helpers'

const theme = {
Expand Down Expand Up @@ -52,7 +52,7 @@ test('responsive', () => {
test('all', () => {
const result = toStyles(textStyle({
theme,
textStyle: cs('responsive', 'heading')
textStyle: [ 'responsive', 'heading' ]
}))

expect(result).toEqual({
Expand All @@ -68,7 +68,7 @@ test('all', () => {
test('variant', () => {
const result = toStyles(textStyle.variant({
theme,
variant: cs('responsive', 'heading')
variant: [ 'responsive', 'heading' ]
}))

expect(result).toEqual({
Expand Down

0 comments on commit 2ea8967

Please sign in to comment.