I am trying to convert the following line to Cljs,
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });
What would be the corresponding map for,
{ enableHighAccuracy: true }
in ClojureScript? Is enableHighAccuracy a symbol?
If you're using interop with a library (such as geolocation, in your case), and it expects a JavaScript object, you'll need to pass it a standard JavaScript object, not a Clojure map.
You can construct one of these in ClojureScript by using the js-obj function with no arguments. This will return an empty JavaScript with no fields; you can then add fields using the aset function.
So your code would be something like:
(let [arg (js-obj)]
(aset arg "enableHighAccuracy" true)
(.watchPosition (.geolocation navigator) on-success on-error arg))
If this is something you find yourself doing a lot, it's easy to write a utility function to convert a ClojureScript map into a JavaScript object using whatever defaults you like; an example of such a function can be found in this gist; https://gist.github.com/1658431
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With