试剂打嗝中的 :<> 是什么?

Jac*_*rui 5 clojure hiccup

我不明白以下代码中的标签“:<>” 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"]]])
Run Code Online (Sandbox Code Playgroud)

谁可以帮我这个事?

Ala*_*son 7

在前面的答案中添加更多细节,将fragment被拼接到周围的列表中,而不是创建子元素。这样一来,与常规运算符相比,它就类似于unquoted-splicingClojure 中的运算符。一个例子:~@unquote~

(defn middle-seq       [] [    :d :e :f])
(defn middle-seq-frag  [] [:<> :d :e :f])
Run Code Online (Sandbox Code Playgroud)

当用于创建试剂组件时,我们看到了差异:

[: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]
Run Code Online (Sandbox Code Playgroud)

否则,您将不得不重组输入并使用concat

(vec
  (concat
    [:a :b :c]
    (middle-seq) 
    [:g :h :i] ))          ;=> [:a :b :c :d :e :f :g :h :i]
Run Code Online (Sandbox Code Playgroud)


Mic*_*ent 5

那就是创建一个 React Fragment:

https://reactjs.org/docs/fragments.html