Accessing defrecord methods in ClojureScript Figwheel

350 Views Asked by At

I have some code in cljc files which compiles to both Clojure and ClojureScript.

in protocols.cljc

(defprotocol Transformable ".." 
    (scale [this scalar] "" ) ...)

in pattern.cljc

(defrecord APattern [paths]
    Transformable
      (scale [this s] (...)) ...)

in another.cljc

(defn f [pattern] (.scale pattern (/ 1 2)) )

And in core.cljs

(another/f pattern)

However, I'm getting an error on the browser console

TypeError: pattern.scale is not a function

Checking the fields of pattern object in core.cljs (using js-keys) shows me that the object has something called

"patterning$protocols$Transformable$scale$arity$2"

which looks like my function. So am I just doing something wrong to access it in ClojureScript? Does . notation not work? Do I need to do something else?

1

There are 1 best solutions below

4
On

Calls to protocol functions are just like calls to any other function. So your f function should look like:

(require 'protocols)
(defn f [pattern] (protocols/scale pattern (/ 1 2)) )