This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-26
Channels
- # beginners (74)
- # cider (3)
- # cljsrn (1)
- # clojure (182)
- # clojure-dev (4)
- # clojure-europe (1)
- # clojure-spec (5)
- # clojure-uk (58)
- # clojurescript (44)
- # core-async (5)
- # core-logic (10)
- # cursive (6)
- # datomic (13)
- # duct (1)
- # fulcro (2)
- # graalvm (4)
- # leiningen (1)
- # off-topic (7)
- # overtone (6)
- # random (3)
- # re-frame (17)
- # reitit (2)
- # shadow-cljs (6)
- # spacemacs (4)
- # sql (12)
- # tools-deps (3)
Hello
are there any examples of extending JS classes in cljs (reagent + re-frame)?
Here is SO post i'd like to use but i am not sure how to create this code with cljs
https://stackoverflow.com/questions/54555877/can-i-use-overlappingmarkerspiderfier-with-react-google-maps
Would i use something like reagent/create-class
and then try to interop it or ?
Are there examples of this that i could use as reference?
Thanks in advance
So you want to have the same exact code, just written in CLJS? Or do you want to have something different, maybe a different base class?
If it's the first one, you don't have to do anything special because the React.Component
base class will added for you by Reagent. You may have to use reagent.core.reactify-component
when you pass Spiderfy
to GoogleMap
though - I'm not sure.
Ah, my bad - the SO version relies on the legacy React context passing (https://reactjs.org/docs/legacy-context.html) which has been supersede by context providers. The the react-google-maps
still uses the legacy context.
So it seems that you're right and you will have to use reagent/create-class
and specify the :context-types
property, just as in the SO version.
import AsyncStorage from '@react-native-community/async-storage';
I’ve had issues with this, it can’t find the lib.(def rn (js/require "@react-native-community/async-storage"))
(def as (.-AsyncStorage rn))
This is my cljs code. Has anyone had similar issues? I’ve linked the library.how do I check that? I called
(str rn)
it gave me
"[object Object]"
Update: I was able to call
(.-AsyncStorage rn)
and it gave me an object:
#js {:_getRequests #js [], :_getKeys #js [], :_immediate nil, :getItem #object[getItem], :setItem #object[setItem], :removeItem #object[removeItem], :mergeItem #object[mergeItem], :clear #object[clear], :getAllKeys #object[getAllKeys], :flushGetRequests #object[flushGetRequests], :multiGet #object[multiGet], :multiSet #object[multiSet], :multiRemove #object[multiRemove], :multiMerge #object[multiMerge]}
no I must be calling it wrong…
This is how I’m calling it
(<! (await (. as getItem token-name)))]
inside a go-block of course
And I still get this error in the simulator:
ah ok, thanks for the attention anyway 🙂
@U2FRKM4TW it might help if you see how it supposed to be called
Yeah, I've seen the example. But it doesn't seem like it has anything to do with that error above since it doesn't even mention AsyncStorate
.
hmm yeah, maybe I fucked up in the ios config
is there a reason to prefer goog.object/get
over just (.-size file)
? Trying to find documentation which might instruct why to choose one over the other
When using leaflet.js, I had to resort on goog.object to avoid null pointers with advanced compilation.
study your compiler externs, young Padawan: https://github.com/google/closure-compiler/blob/master/externs/browser/w3c_fileapi.js#L43 https://github.com/google/closure-compiler/blob/master/externs/browser/w3c_fileapi.js#L77
in other words, .-size
on js/File
should be never renamed in advanced compilation, because such renaming should be prevented by externs bundled with the google closure compiler
in theoretical case the extern is missing .-size
would get renamed
by using gobj/get
you use the force to prevent renaming under any circumstances
So no helper function could work on a “(deftype foo [size])” and js/File if it called (.-size x)? Because the foo’s size and the file’s size names might diverge?
google closure compiler can track the difference and rename foo’s size but leave js/File’s size intact
ah, I see your point, test it, I would guess common helper fn called on both would compile into two distinct helper fns or get inlined
I ran it under a simple test and the “size” property was never renamed even on the deftype. But I wonder if it might under a larger program. That’s why I was wondering if this was documented anywhere
try to use less common name maybe, there could be an extern Object.prototype.size
defined somewhere
anyways, take my comments with a grain of salt, I’m no externs expert, this is my opionon about them 🙂 https://github.com/binaryage/cljs-oops#externs-from-hell
as file
is a js/File
, I prefer (.-size file)
If it was a json like {"size": 42}
, (gobj/get file "size")
Actually, I could get around this renaming problem by adding the ^js metadata to any vars I wanted to be preserved and of course by turning on the infer-externes key in Figwheel ...