Created
June 19, 2015 16:39
-
-
Save dadair-ca/e897748bca5e264f5298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(comment | |
I'm trying to build a very simple clojurescript app using re-frame (& reagent, secretary), | |
and I am getting the following error in the console, that I can't seem to debug: | |
Error: No protocol method IDeref.-deref defined for type cljs.core/PersistentArrayMap: {:name "Black Temple", :snippet "25-man raid"} | |
) | |
(ns raid-commander.core | |
(:require [reagent.core :as reagent :refer [atom]] | |
[reagent.session :as session] | |
[secretary.core :as secretary :include-macros true] | |
[goog.events :as events] | |
[goog.history.EventType :as EventType] | |
[re-frame.core :as re-frame]) | |
(:require-macros [reagent.ratom :refer [reaction]]) | |
(:import goog.History)) | |
;; ------------------------- | |
;; Re-frame data | |
(def initial-state | |
{:raids [{:name "Black Temple" :snippet "25-man raid"} | |
{:name "Tempest Keep" :snippet "25-man raid"} | |
{:name "Karazan" :snippet "10-man raid"}]}) | |
;; ------------------------- | |
;; Event Handlers | |
(re-frame/register-handler | |
:initialize | |
(fn | |
[db _] | |
(merge db initial-state))) | |
;; ------------------------- | |
;; Subscriptions | |
(re-frame/register-sub | |
:raids | |
(fn | |
[db _] | |
(reaction (:raids @db)))) | |
;; ------------------------- | |
;; Views | |
(defn raid-component [raid] | |
[:li | |
[:span (:name @raid)] | |
[:p (:snippet @raid)]]) | |
(defn raids-component [] | |
(let [raids (re-frame/subscribe [:raids])] | |
(fn [] | |
[:ul | |
(for [raid @raids] ^{:key raid} [raid-component raid])]))) | |
(defn home-page [] | |
[:div [raids-component]]) | |
(defn current-page [] | |
[:div [(session/get :current-page)]]) | |
;; ------------------------- | |
;; Routes | |
(secretary/set-config! :prefix "#") | |
(secretary/defroute "/" [] | |
(session/put! :current-page #'home-page)) | |
;; ------------------------- | |
;; History | |
;; must be called after routes have been defined | |
(defn hook-browser-navigation! [] | |
(doto (History.) | |
(events/listen | |
EventType/NAVIGATE | |
(fn [event] | |
(secretary/dispatch! (.-token event)))) | |
(.setEnabled true))) | |
;; ------------------------- | |
;; Initialize app | |
(defn mount-root [] | |
(reagent/render [current-page] (.getElementById js/document "app"))) | |
(defn init! [] | |
(hook-browser-navigation!) | |
(re-frame/dispatch [:initialize]) | |
(mount-root)) |
Thanks. I killed about an hour trying to figure the same problem out and your comment helped me.
I am still confused why deref is not needed here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lines 49/50 had:
when they needed