reagent hiccup中的:<>是什么?

9
我不理解以下代码中的标签":<>"。 clojure re-frame todomvc
(defn todo-app
  []
  [:<>
   [:section#todoapp
    [task-entry]
    (when (seq @(subscribe [:todos]))
      [task-list])
    [footer-controls]]
   [:footer#info
    [:p "Double-click to edit a todo"]]])

有人能帮我解决这个问题吗?


1
主题行应明确指定re-frame。这不是标准hiccup的功能。 - Biped Phill
1
试剂剂量。 - Michiel Borkent
2个回答

9

请参阅 reagent 文档:https://github.com/reagent-project/reagent/blob/master/doc/CreatingReagentComponents.md - Dave Liepmann

7

对于之前的回答,我们再加入一些细节说明。 fragment 会被插入到一个包含列表中,而不是创建一个子元素。这种方式类似于Clojure中的 unquoted-splicing 运算符 ~@ 相对于常规的 unquote 运算符 ~。一个例子:

(defn middle-seq       [] [    :d :e :f])
(defn middle-seq-frag  [] [:<> :d :e :f])

当用于创建 Reagent 组件时,我们可以看到区别:

[:a :b :c (middle-seq)      :g :h :i]    ;=> [:a :b :c [:d :e :f] :g :h :i]
[:a :b :c (middle-seq-frag) :g :h :i]    ;=> [:a :b :c  :d :e :f  :g :h :i]

否则,你将不得不重新构造输入并使用concat:
(vec
  (concat
    [:a :b :c]
    (middle-seq) 
    [:g :h :i] ))          ;=> [:a :b :c :d :e :f :g :h :i]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接