Om-next Remote Sync Tutorial send-to-chan

I'm probably doing something wrong, but I find that there are some problems in one of the om-next tutorials ; in particular, an example of autocomplete. I managed to find out one of the problems , but there is another problem that causes me some problems.

As soon as I put more than two letters in the input field for autocomplete, the following code:

(defn send-to-chan [c]
  (fn [{:keys [search]} cb]
    (when search
      (let [{[search] :children} (om/query->ast search)
            query (get-in search [:params :query])]
        (put! c [query cb])))))

produces the following error:

Uncaught TypeError: Cannot read property 'call' of undefined
core.js?zx=3jufl8vymlgw [452]   om_tutorial.core.send_to_chan
next.js [3034]  om.next.Reconciler.om$next$protocols$IReconciler$send_BANG_$arity$1
protocols.js [303]  om$next$protocols$send_BANG_
next.js [1656]  anonymous

I am not sure why this is so.

Any help would be greatly appreciated.

+4
source share
3 answers

, -, , .

om . ( , https://clojars.org/repo/).

  1. , . ; [org.omcljs/om "1.0.0-alpha23"]. , , , , . , [org.omcljs/om "1.0.0-alpha29"].

, , .

Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `om_tutorial$core$AutoCompleter`. See https://fb.me/react-warning-keys for more information.

.

BTW. om , . lein clean . om-tutorial/resources/public/js. lein run -m clojure.main script/figwheel.clj.

+2

, "" , React , Om. React , .

factory, . :

(def app-state 
  (atom {:items [{:id 1
                  :title "Foo"}
                 {:id 2
                  :title "Foo"}]}

(defui Item
 static om/IQuery
 (query [this] [:id :title])
 Object
 (render [this]
   (dom/li nil (:title (om/props this))))

;; Specify key function as follows
(def item (om/factory Item {:keyfn :id})

(defui List
 static om/IQuery
 (query [this] [{:items (om/get-query Item)}])
 Object 
 (render [this]
   (dom/ul nil (map item (:items (om/props this)))))

, - , ( ).

, map-indexed .

0

I think the om.next/query-> ast problem is not defined in 1.0.0-alpha23 - it was the source of the call with an undefined error.

Here is the hacker work:

    (defn send-to-chan [c]
      (fn [{:keys [search] :as x} cb]
        (when search ;; e.g. [(:search/results {:query "xxx"})]
          (let [query (-> search first second :query)]
            (put! c [query cb])))))
0
source

Source: https://habr.com/ru/post/1622851/


All Articles