1

我在操作 Om 应用程序中的状态时遇到问题。具体来说,我不知道如何从列表中删除项目。

这是我愚蠢的证明。这是一个被破坏的简化应用程序。https://gist.github.com/rerb/29d10959e71ba1e31e8e

显示两个按钮。按下时,它们应自行移除。

删除第一项后,尝试删除第二项时出现此错误:

   Uncaught Error: No protocol method IDeref.-deref defined for type cljs.core/PersistentArrayMap: {:id 2}

如果我先删除第二个,则在尝试删除第一个时会出现此错误:

   Uncaught Error: Assert failed: Can't put nil in on a channel

我错过了什么简单的事情?我是爱因斯特伦。

4

1 回答 1

4

The function remove returns a sequence, not a vector. Your state went from {:buttons [{:id 1} {:id 2}]} to {:buttons ({:id 1})}. By using into after remove you solve your problems:

(fn [buttons]
  (into [] (remove #(= button-id (:id %)) buttons))))

Note: I tried this with Chestnut and it seems to work. Also, if you are beginning with Om avoid using core.async in the beginning. It is a great complement to Om but using both while learning was too much for me to handle.

于 2015-01-18T02:06:29.343 回答