Last active
August 29, 2015 14:11
-
-
Save rohozhnikoff/4ce6ae07ca30038b23ba to your computer and use it in GitHub Desktop.
declarative classSet for jquery (just for concept)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# global helper | |
makeClassSet = (classFunc) -> | |
return (params) -> | |
classArr = [] | |
for className, exp of classFunc(params) | |
classArr.push(className) if exp | |
return classArr.join(' ') | |
# local helper | |
getColorClasses = makeClassSet(({somePredicate, size}) -> | |
return { | |
'is-danger': not somePredicate | |
'is-success': somePredicate | |
'is-big': size >= 20 | |
'is-normal': size > 10 and size < 20 | |
'is-small': size <= 10 | |
} | |
) | |
# logic | |
console.log getColorClasses({inJson: false, size: 16}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment