7

我不明白以下代码 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"]]])

谁可以帮我这个事?

4

2 回答 2

7

那就是创建一个 React 片段:

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

于 2020-10-03T08:58:49.060 回答
5

在上一个答案中添加更多细节,将其fragment拼接到周围列表中,而不是创建子元素。这样一来,与常规操作符相比,它类似于unquoted-splicingClojure中的操作符。一个例子:~@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]
于 2020-10-04T19:44:23.170 回答