Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
fix(dom-helper): Restores curried functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Feb 16, 2018
1 parent b94b25c commit 8caf337
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ export const tag = curry((tag, value = '', attributes = {}) => {
return `<${tag}${attr}>${value}</${tag}>`
})

export const setStyles = curry((attrs = {}, el) => {
export const setStyles = (attrs = {}) => el => {
Object.keys(attrs).forEach(property => {
el.style[property] = attrs[property]
})

return el
})
}

export const getClasses = compose(filter(identity), el => el.className.split(' '))

export const hasOverflow = el => el.scrollWidth > el.clientWidth

export const addClasses = curry((classes, el) => {
export const addClasses = (classes = []) => el => {
el.className = compose(join(' '), uniq, concat(classes), getClasses)(el)

return el
})
}

export const removeClasses = curry((classes, el) => {
el.className = compose(join(' '), filter(className => !~classes.indexOf(className)), getClasses)(el)

return el
})

export const setAttributes = curry((attrs = {}, el) => {
export const setAttributes = (attrs = {}) => el => {
Object.keys(attrs).forEach(property => {
el.setAttribute(property, attrs[property])
})

return el
})
}
6 changes: 3 additions & 3 deletions src/utils/dom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('tag should create a html tag', t => {
test('setStyles adds styles to a dom node', t => {
const testNode = createNode('div')

setStyles({ color: 'red', width: '200px' }, testNode)
setStyles({ color: 'red', width: '200px' })(testNode)

t.is(testNode.style.color, 'red')
t.is(testNode.style.width, '200px')
Expand All @@ -82,14 +82,14 @@ test('setStyles adds styles to a dom node', t => {
test(`getClasses should return the class names`, t => {
const testNode = createNode('div')

addClasses(['foo', 'bar'], testNode)
addClasses(['foo', 'bar'])(testNode)

t.deepEqual(getClasses(testNode), ['foo', 'bar'])
})

test(`addClasses should add classes to dom elements`, t => {
const testNode = createNode('div')
addClasses(['foo', 'bar'], testNode)
addClasses(['foo', 'bar'])(testNode)

t.is(testNode.className, 'foo bar')
})

0 comments on commit 8caf337

Please sign in to comment.