Last active
July 10, 2016 18:57
-
-
Save wilkerlucio/8d0e129eb714a530ecf56cddb7841169 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; 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)) |
This file contains hidden or 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
;; 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)) |
This file contains hidden or 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
;; 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