This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-25
Channels
- # aleph (2)
- # announcements (7)
- # babashka (6)
- # beginners (53)
- # calva (17)
- # cider (5)
- # clj-kondo (137)
- # cljs-dev (19)
- # cljsrn (14)
- # clojure (74)
- # clojure-conj (9)
- # clojure-europe (13)
- # clojure-houston (1)
- # clojure-italy (16)
- # clojure-nl (21)
- # clojure-spec (3)
- # clojure-uk (9)
- # clojuredesign-podcast (24)
- # clojurescript (85)
- # cursive (11)
- # datomic (28)
- # duct (3)
- # emacs (6)
- # figwheel-main (1)
- # fulcro (68)
- # graalvm (19)
- # graphql (3)
- # joker (32)
- # kaocha (10)
- # lambdaisland (1)
- # malli (50)
- # off-topic (13)
- # other-languages (7)
- # pathom (2)
- # pedestal (14)
- # re-frame (53)
- # reitit (8)
- # shadow-cljs (57)
- # specter (2)
@gr.evocatus it’s certainly possible (see Machiatto for an approach) but IMO it’s not worth the trouble. We are migrating away from a JS/Node.js backend to a Clojure/JVM one, and both dev and ops are just so much better.
Is there some performance benefit to reusing a transit writer rather than creating it for every read operation? The API kind of suggests there is but the docs aren’t explicitly saying “For best performance reuse writer and reader instances.“…
I think if you're using the :json-verbose
output, there's no difference. And if you're using :json
output, reusing the same writer will result in proper caching.
Thanks that makes sense!
Is there a way to access a HTML element lets say [:div#myd "Hello"]
is the element. I access to it with (js/document.getElementById("myd"))
but it doesn't feel right. Is there a CLJS way to access?
Well, there's clojure.browser.dom/get-element
. But it essentially does the exact same thing.
if you're in a react based world there are ref functions. (i wish i could collapse the snippet here back into a link but alas)

@p-himik perhaps more idiomatic API in Clojure world
especially if you do run stuff on JVM as well
Maybe more idiomatic, yes.
But how does using react/createRef
prevent you from running stuff on JVM when you already use React?
you’d have to wrap react api usage into reader conditions, because it’s JS library
I just noticed that I'm getting dangerous use of 'this' in static method hgs.platform.abc.core.NotePrinter
with this code:
(defn NotePrinter []
(this-as this
(.call ABCMusicListener this)))
(set! (.. NotePrinter -prototype)
(js/Object.create (.-prototype ABCMusicListener)))
(set! (.. NotePrinter -prototype -constructor)
ABCMusicListener)
(set! (.. NotePrinter -prototype -enterNote)
(fn [ctx]
(js/console.log "NOTE" ctx)))
Am I doing something wrong here?
Is there a better way to implement NotePrinter
?(defn NotePrinter
"@this {NotePrinter}"
[]
(this-as this
(.call ABCMusicListener this)))
This is Closure Compiler complaining about referring to this
within plain function, providing annotation in doc string will fix it, see https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#this-type
@p-himik (defn ^{:jsdoc ["@constructor"]} NotePrinter [] ...)
would be the correct way to define a custom type. then it'll recognize the other prototype props properly as well
is it required to put annotation into jsdoc meta?
Both approaches seem to work. But I like the :jsdoc
one a bit more because it doesn't require repeating the type's name.
you can put it into the regular docs too but then it will appear as part of the regular docs 😛
Is there any examples online of using AWS Amplify Auth from Cljs?
I'm trying to translate this code and have no idea what is going on lol https://gist.github.com/groundedSAGE/995dc2e14845980fdc547c8ba510169c
There's https://github.com/cjsauer/aws-amplify-cljs as an example but is slightly outdated. Honestly the best approach would just be to use native interop with the Amplify library. https://aws-amplify.github.io/docs/js/authentication One little thing to note is that amplify comes with wrappers for the popular frameworks like Vue and React; trying to use those through interop would be unnecessarily confusing. If you stick with the basic library calls on Auth the process should be straightforward and simple for most authentication needs.
I'm using https://github.com/tonsky/rum to interop with React, and I'd like to put in some https://reactjs.org/docs/error-boundaries.html
it doesn't look like rum.core/build-class
supports getDerivedStateFromError
or componentDidCatch
is there a standard way to do this?
I suppose I could use
(gobj/set prototype "getDerivedStateFromError"
to manually poke handlers inoh, I just spotted
did-catch (collect :did-catch mixins) ;; state error info -> state
(let [err (atom nil)]
(rum/defc error-boundary < {:did-catch
(fn [error info]
(reset! err info))}
[& children]
(if-let [rinfo @err]
[:pre [:code (pr-str rinfo)]]
children)))
seems to do what I want (mostly pinched from https://lilac.town/writing/modern-react-in-cljs-error-boundaries/)Hey all, hope the week has been off to a great start. I am trying to understand the ins and outs of ToDoMVC example with reagent. I am having trouble comprehending the logic behind inputting and storing 'todos' in the table. Why do we want to use LocalStore in this example? Is there a way to do it without local store? Thanks 🙂
part of the requirements for todomvc is that you persist the todos to local storage
If you don't need the local storage, you could just remove the interceptor. https://github.com/day8/re-frame/blob/master/examples/todomvc/src/todomvc/events.cljs#L80
https://github.com/tastejs/todomvc/blob/master/app-spec.md for reference on what todomvc is supposed to do
re-frame
stores the state in the db
that is a reagent.core/atom
https://github.com/day8/re-frame/blob/72f06966b0e6bb40c35607629a5301ef3a9e6640/src/re_frame/db.cljc#L10
oh that's awesome! thanks for the quick replies -- I won't be needing that functionality in my application, but it's a great thing to know!
hey, I am using re-frame
template how do I make lein dev
watch the index.css
that I linked in resources/public/index.html
file?
https://shadow-cljs.github.io/docs/UsersGuide.html#_css_reloading if it is shadow-cljs
I'm trying to use cljs-time recursively check if things are within a certain date and then render them. But for some reason having the symbol of t
there is throwing an error.
(within? (interval
(plus (now) (weeks t))
(plus (now) (weeks (inc t))))
object-in-question)
This is the error message Uncaught Error: Assert failed: (<= (.getTime start) (.getTime end))
You should probably check the actual value of start and end values of the interval
https://github.com/andrewmcveigh/cljs-time/blob/master/src/cljs_time/core.cljs#L142
Seemed to work when I pre-compute the interval.
Must be something to do with within?
I pulled interval out of within and out it in a let binding ‘(let [my-interval (interval (now) (plus (now) (weeks t))])’ then it started working using ‘my-interval’ in ‘within?’. But calling that directly within ‘within?’ It broke ??
Before you had
(interval
(plus (now) (weeks t))
(plus (now) (weeks (inc t))))
Now you have
(interval (now) (plus (now) (weeks t)))
Notice the difference?another re-frame question -- I am trying to update the db based on changes happening in the :select multiple. I am able to log change of :select in console, but not sure how to access the values in select to update the db. code and image for reference below.
ideally, after selecting one (or multiple) , we would call an event-handler function to assoc the change in db
@ablazevix Try Adding %
in that logging statement.
yep, I tried and got a large blurb back
SyntheticEvent {dispatchConfig: {…}, targetInst: FiberNode, dispatchInstances: FiberNode, nativeEvent: Event, _dispatchListeners: ƒ, …} bubbles: (...) cancelable: (...) currentTarget: (...) defaultPrevented: (...) dispatchConfig: null eventPhase: (...) isDefaultPrevented: (...) isPropagationStopped: (...) isTrusted: (...) nativeEvent: (...) target: (...) timeStamp: (...) type: (...) _dispatchInstances: null _dispatchListeners: null _targetInst: null preventDefault: (...) stopPropagation: (...) get bubbles: ƒ () set bubbles: ƒ (val) get cancelable: ƒ () set cancelable: ƒ (val) get currentTarget: ƒ () set currentTarget: ƒ (val) get defaultPrevented: ƒ () set defaultPrevented: ƒ (val) get eventPhase: ƒ () set eventPhase: ƒ (val) get isDefaultPrevented: ƒ () set isDefaultPrevented: ƒ (val) get isPropagationStopped: ƒ () set isPropagationStopped: ƒ (val) get isTrusted: ƒ () set isTrusted: ƒ (val) get nativeEvent: ƒ () set nativeEvent: ƒ (val) get target: ƒ () set target: ƒ (val) get timeStamp: ƒ () set timeStamp: ƒ (val) get type: ƒ () set type: ƒ (val) get preventDefault: ƒ () set preventDefault: ƒ (val) get stopPropagation: ƒ () set stopPropagation: ƒ (val) proto__: Object
do you find yourself often looking up react solutions to solve reagent problems?
In essence, it just allows you to write React applications by using ClojureScript and sticking with more or less idiomatic ClojureScript code.
oh thats helpful! I'll try doing that too, but might need more react skills then
Just note that Reagent is lagging a bit. E.g. AFAIK there's no support for React hooks.
Also, given your last comment under the image, you probably want to set :on-change
to something like #(dispatch [:headers-ev/select select-id (.. % -target -value)])
where :headers-ev/select
is a re-frame event registered somewhere.
I'm not sure whether (.. % -target -value)
will work properly in production, where you'd use advanced optimizations. But that's a different question.
yep, here's the solution for logging the change
#(js/console.log (-> % .-target .-value))
To try things out to see how they turn into JS you can use http://app.klipse.tech/
that's awesome man.. the way you can interact with objects..
You may like https://github.com/binaryage/cljs-oops It allows using things like (oget x :?a.?b.?c)
where none of the fields may exist - it will not throw an error, it will return just nil
.
Although be sure to use it primarily for data (i.e. JSON). There are various concerns when using it with proper objects due to how stuff gets compiled.
Also, since it's Clojure where we can use macros, (oget x :?a.?b.?c)
is actually turned into a minimal JavaScript, without any overhead whatsoever.
haha, definitely on the map, though still some time before I get comfortable with those. 🙂
I have some cljc that uses alias
which does not work in cljs because there is no alias
function. What do people use in place of Clojure's alias
function?
I assume the absence of the function has something to do with how CLJS is compiled.
I've never used alias
myself. Out of interest - how do you use it?
I probably misunderstand something. How is it different from (require '[myapp.core :as core])
?
Ah, so it doesn't require the existence of the referenced namespace, which is useful for keywords. I see.
there is no replacement for alias currently. only option is to use the full namespace
Oof. A bit surprised given alias
is used a lot with Spec. Typically alias
is used to prevent circular ns dependencies (e.g., core -> specs -> core).