This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-11
Channels
- # adventofcode (116)
- # aleph (10)
- # announcements (2)
- # beginners (67)
- # boot (3)
- # calva (17)
- # cider (8)
- # cljdoc (27)
- # cljsrn (6)
- # clojure (144)
- # clojure-austin (3)
- # clojure-boston (1)
- # clojure-dev (25)
- # clojure-europe (4)
- # clojure-italy (26)
- # clojure-losangeles (4)
- # clojure-nl (28)
- # clojure-russia (1)
- # clojure-uk (34)
- # clojurescript (130)
- # cursive (20)
- # datomic (69)
- # emacs (14)
- # figwheel-main (2)
- # fulcro (31)
- # graphql (3)
- # hyperfiddle (3)
- # jobs (1)
- # jobs-discuss (1)
- # kaocha (1)
- # leiningen (2)
- # lumo (2)
- # nrepl (1)
- # off-topic (182)
- # onyx (5)
- # re-frame (88)
- # reagent (12)
- # reitit (2)
- # ring-swagger (13)
- # shadow-cljs (136)
- # tools-deps (28)
- # vim (4)
is there some kind of.... like goog/object.call-this-objects-method-without-losing-the-`this`-context function?
im trying to call the aws sdk and I'm getting hit with this.makeRequest is not a function
even though I can clearly inspect said object and see said function
hmm, interesting. the latter two I didn't know about. I ended up using the bind solution
how do i invoke a method on a javascript object by name?
in JS i would do foo[method]();
((goog.object/get foo "method"))
isn’t working
@currentoor it works
yeah that works but if i do the same with the Big.js library then i get this error
((aget x "lt") (n->big 4)))
TypeError: this.cmp is not a function
js/this
is being changed i believe
if the js lib uses this
then it won’t work unless you are careful to preserve it, but that is more general problem
that works!
thanks!
you can look at generated js code in repl: (.toString (fn [] ((goog.object/get foo "method"))))
ah i see
In Clojure, the java class hierarchy participates pretty seamlessly with the isa?
hierarchy:
(derive java.util.Map ::collection)
(derive java.util.Collection ::collection)
(defmulti foo class)
(defmethod foo ::collection [c] :a-collection)
(defmethod foo String [s] :a-string)
(foo [])
:a-collection
(foo (java.util.HashMap.))
:a-collection
(foo "bar")
:a-string
How do we achieve a similar thing in ClojureScript?The closest thing I can come up with is:
(derive (type {}) ::collection)
(derive (type []) ::collection)
(defmulti foo type)
(defmethod foo ::collection [c] :a-collection)
(defmethod foo (type "") [c] :a-string)
(foo [])
:a-collection
(foo "bar")
:a-string
It's not quite the same though. I'd prefer to pass in type literals. And cljs types don't appear to ship with any ancestors out of the box.Has anyone here used some dashboard template built on ReactJs to create single page applications on ClojureScript?
Something like this: https://demos.creative-tim.com/material-dashboard-react/#/dashboard
Still, does the docstring for isa?
reflect the current implementation? ... via a JavaScript type inheritance relationship
... The source doesn't appear to indicate the prototype tree is being walked atm https://cljs.github.io/api/cljs.core/isaQMARK
@dannyt yeah I don't think think the hierarchy stuff (around JS types) is well supported - not much usage, thus few reports
ClojureScript's own types are tagged so we know - but you cannot do this for anything else
if I'm developing a library, what's the proper way to inform consumers to install npm deps for both figwheel-main, lein-figwheel and shadow-cljs?
@lilactown you usually need a deps.cljs
file containing :npm-deps
on the classpath
The compiler then should take care of the rest
note :npm-deps
is a bit complected though - it pulls in deps but also gets the compiler to process those through Closure
I think that at least for react & react-dom, they're amenable to processing through gcc
@lilactown still I can't say that I would recommend going down this route
making dependencies work consistently over the standard stuff and shadow-cljs is probably more trouble than it's worth at this time
I have to say that I am compiling libraries with npm
deps in shadow and never had a problem so far
on node though, don't know browser, which might be different
@dnolen Yeah, I didn't really understand how it would have worked either. Thanks for the clarification. I'm exploring isa?
right now so I'll let you know if I notice anything salient.
Hello everyone :) I would like to develop a webapp mainly for data visual with user interaction. I wondered if anyone had advice? I am stuck at choosing my “styling” layer (bulma, material-design-lite or react-md)?
I guess I just need to know how to tell consumers to install my library, which depends on react - should they use :npm-deps
in their project? cljsjs?
I'm trying to write a cross-compatible / macro that uses let
in its macroexpansion. But it turns out clojure.core/let
potentially includes clojure.lang.PersistentHashMap/create
in its macroexpansion (to support the "seq as map" use case), causing a warning on ClojureScript. Is there a way I can intelligently pick between clojure.core/let
and cljs.core/let
in my macro depending on which language i'm targeting?
Alternative question, does this lack of let
portability seem like a flaw in either of the underlying languages, or is the discrepancy in let
implementations by design?
I could have sworn I wrote a cross compatible macro with a let in it recently, with no issues. Is this an edge case?
this only comes up if you use map-destructuring as one of the let bindings
user=> (macroexpand `(let [{:keys [~'x]} {:x 1}]))
(let* [map__81766 {:x 1} map__81766 (if (clojure.core/seq? map__81766) (clojure.lang.PersistentHashMap/create (clojure.core/seq map__81766)) map__81766) x (clojure.core/get map__81766 :x)])
@aengelberg sounds like you're doing some manual stuff
manual stuff?
you mean
`let => clojure.core/let
?oh I see, so you're saying I must be macroexpanding my let
somewhere before it reaches cljs, otherwise it would work?
ok thanks for the clue
I thought I wasn't doing that, but will dig around
ahhhh yeah I'm calling clojure.core/destructure
during my macro logic
sad times
there's not a proper API, but it's pretty easy to know that you're in Clojure / ClojureScript by looking at &env
good to know
has anyone ever run into a situation with core.async where it just... doesn't block? Like, the takes are just succeeding without the put having occurred yet. It's just pulling empty values
@neo2551 I've heard good things about bulma recently. In my experience, going with a pure css thing will interoperate more easily with react, unless the thing is made for react or you're a react life-cycle ranger.
@idiomancy as suggested, that would happen if the channel is closed
(sort-by not giving me expected results..
how confident are you in your comparator? often bugs arise when the comparator is does not impose a total order
well i have a bunch of posts, i'm rendering them into html, i'm (sort-by'ing) the collection as it gets rendered... but no matter wha ti do the sequnce does not change
@dnolen yeah, I got confused because the async/map function, upon receiving an initial value of nil (becuase the step before it had erred, ), it passed an empty sequence through to the next function rather than just closing.
anyway, i'm certain it's an easy fix, due to the list like nature of this recursive display... but i'll have to figure out exactly when to "sort-by"
does cljs use sort-by differently?
@sova it's hard to know what's wrong because we don't know how you're comparing them
AFAICT sort-by
works the same as Clojure, but there might be something weird with the function you're using to compare them
buncha maps, comparing on a particular key
if, for instance, you used a form 2 but didnt pass through the args to the inner function
(rum/defc render-item < rum/reactive show-fresh [pid]
(let [post-coll (rum/react posts) ;atom
input-coll (rum/react input-state)
cids (return-comment-ids pid)]
;(prn cids)
(if (empty? (return-comment-ids pid))
(let [noc-post (first (filter #(= pid (:id %)) post-coll))]
[:div.nocomments {:id pid :class "genpost"}
[:div.padleft {:on-click (fn [e] (do
(.log js/console "Freshly selected: " pid)
(.stopPropagation e)
(swap! input-state assoc-in [:inputs 0 :selected-parent] pid)
(swap! input-state assoc-in [:inputs 0 :selected-child] (return-comment-ids pid))))}
[:div.item-contents.genpost {:class (cond (= pid (get-in @input-state [:inputs 0 :selected-parent])) "selectedParent"
(some #(= % pid) (get-in @input-state [:inputs 0 :selected-child])) "selectedChild")} (:contents noc-post)
[:div.item-author (:author noc-post)]
[:div.rate
[:div.item-rate-doubleplus "++"]
[:div.item-rate-plus "+"]
[:div.item-rate-minus "-"]
[:div.item-rating (/ (:ratings-total noc-post) (:number-of-ratings noc-post))]]]]])
;lest the post has comments and needs more renders in pocket.
(let [com-post (first (filter #(= pid (:id %)) (sort-by #(/ (:ratings-total %) (:number-of-ratings %)) post-coll)))]
[:div.hascomments {:id pid }
[:div.padleft {:on-click (fn [e] (do
(.log js/console "Freshly selected: " pid)
(.stopPropagation e)
(swap! input-state assoc-in [:inputs 0 :selected-parent] pid)
(swap! input-state assoc-in [:inputs 0 :selected-child] (return-comment-ids pid))))}
[:div.item-contents.genpost {:class (cond (= pid (get-in @input-state [:inputs 0 :selected-parent])) "selectedParent"
(some #(= % pid) (get-in @input-state [:inputs 0 :selected-child])) "selectedChild")} (:contents com-post)
[:div.item-author (:author com-post)]
[:div.rate
[:div.item-rate-doubleplus "++"]
[:div.item-rate-plus "+"]
[:div.item-rate-minus "-"]
[:div.item-rating (/ (:ratings-total com-post) (:number-of-ratings com-post))]]]
(map render-item cids)]]))))
two branches: if it has a comment print out the post and call again the fxn... if it has no comments just print the post
each post is just a map with {:contents "" :author "" :timestamp "" :number-of-ratings 2 :ratings-total 177}
the rendering works fine for showing indented branches of comments in the comment tree. but, i'd like to sort them by :ratings-total or the quotient of ratings-total and number-of-ratings. but anyway, no matter where i throw in a (sort-by :number-of-ratings ...)
there's no change in the data on the page. despite a visible page refresh
in this specific example yes
but i gotta make sure my data is covering this test case ... so standby pls ^_^
okay yeah totally
ahhh good idea
my comment-ids function looks like this, but i need to sort the returned comments by a key...
:comments is a sequence [ ]
how can i go from (44 22) to [44 22] ?
Can you get the view to update via other means? I'm betting on @idiomancy's guess.
maybe i need to sort the atom
and then it will do what i want
but i'm not certain how to sort it
well dig this, i have a comment and it has children, and the children are now competing on rating, i have to check which one is higher before rendering, or just have the atom have the higher one first. it's a fun puzzle, since i'm building a tree by reference
Yeah that's interesting. Does a user interaction somehow trigger the resort without altering the atom's state?
rum is great, you just put > rum/reactive and (rum/react @posts)
and it's more-or-less an observable that will trigger a ui update on changes to that atom.
I'd think all views that depend on it would update on any change then, but rum may make less assumptions about what you want rendered, iirc, so you may have to do some stuff manually.
yes, the tricky part is how i'm storing my comments
i'm storing them as a list of references. and i just noticed that to "sort them" means to sort that little list of references in each post in the atom.
Looks like..
(let [sort-me-id 77
spot (first (first (filter #(= (:id (second %)) sort-me-id) (map-indexed vector @posts))))
sorted-comments (map :id
(sort-by :number-of-ratings >
(map get-post-by-id
(:comments (get-post-by-id sort-me-id)))))]
(swap! posts assoc-in [spot :comments] sorted-comments ))
probably a dozen cleaner ways to do it