Skip to content

Commit 21ac22a

Browse files
committed
Skip duplicated classNames in themr function
1 parent ed520a2 commit 21ac22a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/components/themr.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function themeable(original = {}, mixin) {
178178

179179
//merging reducer
180180
(result, key) => {
181-
const originalValue = original[key]
181+
const originalValue = original[key] || ''
182182
const mixinValue = mixin[key]
183183

184184
let newValue
@@ -189,7 +189,10 @@ export function themeable(original = {}, mixin) {
189189
newValue = themeable(originalValue, mixinValue)
190190
} else {
191191
//either concat or take mixin value
192-
newValue = originalValue ? `${originalValue} ${mixinValue}` : mixinValue
192+
newValue = originalValue.split(' ')
193+
.concat(mixinValue.split(' '))
194+
.filter((item, pos, self) => self.indexOf(item) === pos && item !== '')
195+
.join(' ')
193196
}
194197

195198
return {

test/components/themr.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,12 @@ describe('themeable function', () => {
547547
const result = themeable(themeA, themeB)
548548
expect(result).toEqual(expected)
549549
})
550+
551+
it('should skip dupplicated keys classNames', () => {
552+
const themeA = { test: 'test' }
553+
const themeB = { test: 'test test2' }
554+
const expected = { test: 'test test2' }
555+
const result = themeable(themeA, themeB)
556+
expect(result).toEqual(expected)
557+
})
550558
})

0 commit comments

Comments
 (0)