Skip to content

Instantly share code, notes, and snippets.

@mmower
Created October 6, 2015 21:15
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 mmower/c73f1d93528323717217 to your computer and use it in GitHub Desktop.
Save mmower/c73f1d93528323717217 to your computer and use it in GitHub Desktop.
; fate.core
(ns fate.core)
(defprotocol Component
"The Component protocol is used to allow us to refer to components using a keyword
(the component-key) without requiring them to have a keyword field, this also has
the useful property that, by extending the protocol to the Keyword type we can refer
to components also by this keyword transparently."
(component-key [this]))
; CLJ code using fate.core
(clojure.core/defrecord BarComponent [x y] fate.core/Component (fate.core/component-key [this__18135__auto] :bar))
; CLJS code using fate.core
(clojure.core/defrecord BarComponent [x y] fate.core/Component (fate.core/component-key [this__18135__auto] :bar))
fails with
WARNING: Bad method signature in protocol implementation, fate.core/Component does not declare method called fate.core/component-key at line 1 <cljs repl>
clojure.lang.ExceptionInfo: set! target must be a field or a symbol naming a var at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :tag :cljs/analysis-error}
; however
(clojure.core/defrecord BarComponent [x y] fate.core/Component (component-key [this__18135__auto] :bar))
; seems to work, i.e. component-key is no longer fully qualified
; any ideas why this difference between CLJ and CLJS?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment