Skip to content

Instantly share code, notes, and snippets.

@dadair-ca
Created June 19, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadair-ca/e897748bca5e264f5298 to your computer and use it in GitHub Desktop.
Save dadair-ca/e897748bca5e264f5298 to your computer and use it in GitHub Desktop.
(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))
@dadair-ca
Copy link
Author

Lines 49/50 had:

@raids

when they needed

raids

@vitaly-pushkar
Copy link

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