Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;; this works under normal compilation
;; on advanced it fails with: https://www.dropbox.com/s/krf7c38bwykzldl/Screenshot%202016-07-10%2015.48.16.png?dl=0
(defprotocol SampleProtocol
(some-method [this]))
(om/defui ^:once SampleClass
static om/IQuery
(query [_] [:query])
static SampleProtocol
(some-method [this]
(om/get-query this))
Object
(render [this] this))
(defn get-sample-class [] SampleClass)
(let [c (get-sample-class)]
(js/console.log "method" (some-method c)))
(def sample-class (om/factory SampleClass))
;; by adding the instantiation hack (line 24) the method is called on normal and advanced compilations
;; but it fails right after, when trying to call get-query, the get-query call thinks the call is for an instance
;; the original intent was to calling it on the class, this results on get-query trying to access properties
;; that are not present, triggering an error, so the result fails on both normal and advanced compilations
;; error: https://www.dropbox.com/s/jjks6v7ap78lwjt/Screenshot%202016-07-10%2015.50.50.png?dl=0
(defprotocol SampleProtocol
(some-method [this]))
(om/defui ^:once SampleClass
static om/IQuery
(query [_] [:query])
static SampleProtocol
(some-method [this]
(om/get-query this))
Object
(render [this] this))
(defn get-sample-class [] SampleClass)
(let [c (get-sample-class)
c (if (goog/isFunction c)
(js/Object.create (.-prototype c)))]
(js/console.log "method" (some-method c)))
(def sample-class (om/factory SampleClass))
;; now trying to hack into `om$isComponent` so that `get-query` (line 22) would consider it a class
;; with this hack the code works again for normal compilations, but still fails at advanced, it's like
;; we didn't set the `om$isComponent` on the advanced
;; error: https://www.dropbox.com/s/pclefgk7tq6vjsx/Screenshot%202016-07-10%2015.55.56.png?dl=0
(defprotocol SampleProtocol
(some-method [this]))
(om/defui ^:once SampleClass
static om/IQuery
(query [_] [:query])
static SampleProtocol
(some-method [this]
(om/get-query this))
Object
(render [this] this))
(defn get-sample-class [] SampleClass)
(let [c (get-sample-class)
c (if (goog/isFunction c)
(doto (js/Object.create (.-prototype c))
(gobj/set "om$isComponent" false)))]
(js/console.log "method" (some-method c)))
(def sample-class (om/factory SampleClass))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.