Hi
I'm not sure why you see that particular error, but init-state should return
the initial component local state. Looking at you code my guess is that you
either want something like
om/IInitState
(init-state [this]
{:departments []})
or no initial state at all since you're using IRender and not IRenderState.
On Sunday, September 21, 2014 4:44:13 PM UTC+3, simon lomax wrote:
> I've been following a tutorial and adapted slightly. For some reason I keep
> getting this error when ever I try to transact! or update! the app-state:
>
> Uncaught Error: No protocol method ICollection.-conj defined for type
> cljs.core/Atom: [object Object]
>
> Does anyone know what I'm doing wrong. Heres the code:
>
> (ns dashboard.core
> (:require-macros [cljs.core.async.macros :refer [go alt!]])
> (:require [goog.events :as events]
> [cljs.core.async :refer [put! <! >! chan timeout]]
> [om.core :as om :include-macros true]
> [om.dom :as dom :include-macros true]
> [cljs-http.client :as http]))
>
> (enable-console-print!)
>
> (println "Hello world!")
>
> (def app-state
> (atom {}))
>
> (defn fetch-departments
> [url]
> (let [c (chan)]
> (go
> ;;(let [{departments :body} (<! (http/get url))]
> (let [departments [{:department "Departement 1"} {:department
> "Departement 2"}]]
> (>! c (vec departments))))
> c))
>
> (defn department [{:keys [department]} owner opts]
> (om/component
> (dom/li nil department)))
>
>
> (defn department-list [{:keys [departments]}]
> (om/component
> (apply dom/ul nil
> (om/build-all department departments))))
>
> (defn departments-box [app owner opts]
> (reify
> om/IInitState
> (init-state [_]
> ;; THIS IS THE LINE THAT ERRORS
> (om/transact! app :departments (fn [] [])))
>
> om/IWillMount
> (will-mount [_]
> (go (while true
> (let [departments (<! (fetch-departments (:url opts)))]
> (.log js/console (pr-str departments))
> (om/update! app #(assoc % :departments departments))
> )
> (<! (timeout (:poll-interval opts))))))
> om/IRender
> (render [_]
> (dom/h1 nil "Departments")
> (om/build department-list app))))
>
>
> (defn om-app [app owner]
> (om/component
> (dom/div nil
> (om/build departments-box app
> {:opts {:url "http://localhost:3030/api/departments"
> :poll-interval 2000}}))))
>
> (om/root om-app app-state {:target (. js/document (getElementById
> "main-container"))})
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.