在JavaScript中,处理动态类的一种常见方法是使用classnames库。
我找不到任何替代的ClojureScript解决方案,似乎大多数人都可以在(str ...)中使用内联if语句,比如:
(str "location flex-column border-box" (if is-current " current"))在我看来,这似乎是脆弱和乏味的(参见空间处理)。
我希望这个函数的工作方式如下:
(class-names {
:location true
:flex-column true
:border-box true
:current is-current
})
; -> "location flex-column border-box"
; or "location flex-column border-box current"或者像这样
(class-names "location" "flex-column" "border-box" {
:current is-current
})当然,手动编写这样的函数应该不难,但我认为这应该已经以某种方式解决了。
发布于 2017-07-03 07:40:12
底层类名JavaScript库及其所有性能优化都可以通过cljsjs:https://github.com/cljsjs/packages/blob/master/classnames/README.md获得
https://stackoverflow.com/questions/44868664
复制相似问题