I just started using Om (a reaction-based library for ClojureScript). I would like to filter the list based on user input. The following works, but the solution seems complicated. Is there a better one?
(ns om-tut.core (:require-macros [cljs.core.async.macros :refer [go]]) (:require [om.core :as om :include-macros true] [om.dom :as dom :include-macros true] [clojure.string :as string])) (enable-console-print!) (def app-state (atom {:list ["Lion" "Zebra" "Buffalo" "Antelope"]})) (defn handle-change [e owner {:keys [text]}] (om/set-state! owner :data (vec (filter (fn [x] (> (.indexOf x(.. e -target -value)) -1)) (@app_state :list)))) (om/set-state! owner :text (.. e -target -value))) (defn list-view [app owner] (reify om/IInitState (init-state [_] {:text nil :data (:list app) }) om/IRenderState (render-state [this state] (dom/div nil (apply dom/ul #js {:className "animals"} (dom/input #js {:type "text" :ref "animal" :value (:text state) :onChange #(handle-change % owner state)}) (map (fn [text] (dom/li nil text)) (:data state))))))) (om/root list-view app-state {:target (. js/document (getElementById "registry"))})
clojure reactjs om clojurescript
rogergl
source share