Skip to content

Instantly share code, notes, and snippets.

@rohozhnikoff
Last active August 29, 2015 14:11
Show Gist options
  • Save rohozhnikoff/4ce6ae07ca30038b23ba to your computer and use it in GitHub Desktop.
Save rohozhnikoff/4ce6ae07ca30038b23ba to your computer and use it in GitHub Desktop.
declarative classSet for jquery (just for concept)
# 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