This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-11
Channels
- # announcements (1)
- # aws (3)
- # beginners (48)
- # calva (2)
- # cider (47)
- # clj-kondo (1)
- # cljs-dev (23)
- # cljsrn (10)
- # clojure (81)
- # clojure-chicago (4)
- # clojure-europe (3)
- # clojure-greece (4)
- # clojure-italy (8)
- # clojure-losangeles (1)
- # clojure-nl (6)
- # clojure-sanfrancisco (1)
- # clojure-seattle (1)
- # clojure-uk (21)
- # clojurescript (40)
- # core-async (82)
- # cursive (18)
- # datomic (6)
- # duct (11)
- # figwheel-main (4)
- # fulcro (26)
- # jobs-discuss (22)
- # leiningen (18)
- # off-topic (10)
- # pathom (3)
- # re-frame (5)
- # reagent (16)
- # reitit (4)
- # shadow-cljs (8)
- # specter (7)
- # sql (16)
- # tools-deps (58)
- # xtdb (30)
Math
in JavaScript is an object, right? How can I access that object in ClojureScript? I know I can do Math/pow
for example to call a method of it, but how can I view the object without calling any methods? Just doing js/Math
results in #js {}
which is an empty object? I'm confused. 😛
That is because Math
properties are not enumerable: http://zduck.com/2013/non-enumerable-properties-in-javascript/.
You can use getOwnPropertyNames
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames) to get list of properties.
So if you wanted map of properties, you could do:
(->> (.getOwnPropertyNames js/Object js/Math)
(map (fn [prop]
[prop (goog.object/get js/Math prop)]))
(into {}))
@deadghost (js->clj js/Math)
returns {}
are there any projects working on running a self-hosted cljs repl in the browser/in node/electron? 🙂
I've played around a bit with lumo, but from what I can tell, you can't really require it from node
I've read a little on replumb, and I think it's in the right direction, but I don't actually understand what it does
Hi guys ! Question : when using Reagent and cljs-ajax library, what is better place to put loading state ? On local state component Reagent atom or on global state ? Can I use form-2 component like this ? Without using form-3's :component-did-mount ?
(defn my-component []
(let [is-loading? (reagent/atom true)]
(fetch-from-api?) ;; <-- cljs-ajax call
(fn []
(if @is-loading?
[:p "loading..."]
[:p "Content loaded"]))))
Thx 🙂Like that it works, but I must pass the ratom state in the fetch-from-api argument and use :finally to reset! is-loading to nil and I'm sure is not clean, isn't it ?
(fetch-from-api is-loading?)
(defn fetch-from-api
[id is-loading?]
(let [url (str " " id "?api_key=" api_token "&language=fr")]
(GET url
{:handler #(reset! film %)
:finally #(reset! is-loading? nil)
:error-handler (fn [{:keys [status status-text]}]
(js/console.log status status-text))
:response-format :json
:raw true})))
Greetings, I’m requiring an NPM package (material-ui, to be precise) and I learned that if I want to import a single icon I can use the following require line:
Clojure
["@material-ui/icons" :refer [Add]]
This works, however it imports all icons withing @material-ui/icons
instead of just Add
(approx. 5000)
The alternative route to fix this is:
Clojure
["@material-ui/icons/Add" :default Add]
Now we only require Add
and it all works.
My question is, if I want to import 10 icons I’d have to write this 10 times. Is there by any chance a require key like :refer
but only imports what I need?Hi guys, Im trying to build a lib and I need to be able to register a handler for dismount from within a reagent component, without being able to control the component call site. I want to be able to do something like this.
(defn component []
(on-dismout #(js/console.log "dismounted"))
(fn []
[:div]))
I’ve tried a few things, but none of them are ideal.
this kind of gets there
(defn on-dismount [f]
(let [reaction (.-cljsRatom (r/current-component))]
(ratom/add-on-dispose! reaction f)))
but cljsRatom is not defined on first render.
(.-isMounted (.-updater (r/current-component) ) (r/current-component)
requires me to register a polling service and won’t be particularly quick
This also kind of works
(defn on-dismount [f]
(let [id (rand-int 1000)
reaction (ratom/make-reaction (constantly true)
:on-set (constantly nil)
:on-dispose f)]
@reaction
reaction))
But the caller needs to keep derefing the return value, in render cycle
Anyone have an idea?I only read about it today, but I think you might be able to use with-let
and a finally
block
see http://reagent-project.github.io/docs/master/CreatingReagentComponents.html under Appendix B
yeah! but unfortunately I think that requires to change call site, so you’re in the same predicament as a higher order component
maybe not…
(defn mouse-pos []
(r/with-let [pointer (r/atom nil)
handler #(swap! pointer assoc
:x (.-pageX %)
:y (.-pageY %))
_ (.addEventListener js/document "mousemove" handler)]
@pointer
(finally
(.removeEventListener js/document "mousemove" handler))))
(defn tracked-pos []
[:div
"Pointer moved to: "
(str @(r/track mouse-pos))])
Thanks, i’ll experiment
yeah, same problem. Need to keep derefing the reaction for it to not trigger the dispose immediately
oh you need to write the actual function on-dismount
that takes another function, rather than writing a component that runs some code on dismount?
@danieleneal exactly!
Hi guys i got question about interop with react semantic ui i find strange behavior https://codesandbox.io/s/l2mz8yljl7?module=/example.js is the example and i am playing with concept of knowing if view is mobile. so i am using
(-> ui/Responsive
.-onlyMobile
.-maxWidth)
and that works but i wanted to use
(goog-obj/get ui/Responsive #js ["onlyMobile" "maxWidth"])
but that is nil
then i used (goog-obj/get ui/Responsive #js ["onlyMobile"])
and i get #js {:minWidth 320, :maxWidth 767}
then i would have to use something like
(:maxWidth (js->clj (goog-obj/get ui/Responsive #js ["onlyMobile"])
:keywordize-keys true))
or
(get (js->clj (goog-obj/get ui/Responsive #js ["onlyMobile"])) "maxWidth")
in this weird or i am doing something wrong?Hello @lepistane You can use getValueByKeys :
(goog-obj/getValueByKeys ui/Responsive #js ["onlyMobile" "maxWidth"])