This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-19
Channels
- # announcements (9)
- # babashka (5)
- # babashka-sci-dev (23)
- # beginners (160)
- # calva (78)
- # cider (23)
- # clj-commons (2)
- # clj-kondo (5)
- # cljdoc (19)
- # cljs-dev (8)
- # clojure (54)
- # clojure-australia (1)
- # clojure-czech (2)
- # clojure-dev (17)
- # clojure-europe (8)
- # clojure-italy (8)
- # clojure-nl (2)
- # clojure-sg (3)
- # clojure-uk (4)
- # clojurescript (70)
- # community-development (8)
- # core-async (8)
- # cursive (7)
- # datahike (12)
- # datalog (22)
- # datomic (20)
- # events (1)
- # fulcro (43)
- # graalvm (92)
- # gratitude (5)
- # holy-lambda (77)
- # honeysql (1)
- # jobs (1)
- # lsp (111)
- # membrane (70)
- # nextjournal (13)
- # off-topic (73)
- # pathom (1)
- # polylith (8)
- # portal (32)
- # re-frame (3)
- # reagent (4)
- # reitit (5)
- # releases (2)
- # reveal (4)
- # xtdb (22)
Hey, what's your preferred way of implementing user authentication in Clojure and/or ClojureScript.
Thanks.
Good morning! I have a question about the state of affairs regarding externs inference. In the docs I’m reading that aget
should only be used for arrays, not objects. There is also the library cljs-oops
which provides an oget
. It refers to the cljs docs about externs inference, noting:
> Externs inference is very recent feature and looks promising.
That comment was written a few years ago. So my question is: what should I use nowadays for accessing JS objects? Is externs inference good enough that I don’t need to worry about anything? Should I use cljs-oops
? Any insight is much appreciated!
Please note that I have been mostly doing Clojure development, so I’m not too familiar with the exact differences between Clojure and ClojureScript.
when working with code use regular interop and let extern inference to its thing, which just means you sometimes need to provide ^js
hints on things that are JS objects
agree with that... bit more info here https://widdindustries.com/clojurescript-jsinterop/
Is there a way to catch possible instances of items which might need to get type hinted? We’re using oops because we had too many cases of externs not being caught
there is *warn-on-infer*
described here: https://clojurescript.org/guides/externs which will print WARNING: Cannot infer target type in expression ..
I think there is some way to make specific warnings fail the build... or maybe that's in discussion still I can't remember
in shadow-cljs it is default to warn for all of your sources. the default otherwise is only to warn if enabled, so if you are not using shadow-cljs and have not enabled warnings manually then you get no warnings at all
inference still happens but will likely be incomplete due to those missing js hints
IIRC the least invasive solution is to have a fully transparent div on top of it with that tooltip.
Thanks @U2FRKM4TW I have used bootstrap data-toggle ="tooltip"
Can i use a macro or something to generalize my usage of icons here:
(ns app.components.icons.icons
(:require ["@tabler/icons" :refer (IconPlaneDeparture)]))
(defn icon-plane-departure []
(r/as-element [:> IconPlaneDeparture
{:color "#6a35ff"
:stroke 1.25
:size 24}]))
(defn tabler-icon [name]
(r/as-element [:> name {:color "#6a35ff"
:stroke 1.25
:size 24}]))
but you could add a map of strings->components and then use tabler-icon like [tabler-icon “IconPlaneDeparture”]
What if i do something like this:
(ns app.components.icons.icons
(:require [reagent.core :as r]
["@tabler/icons" :as tabler-icons]))
(defn tabler-icon [name]
(r/as-element [:> tabler-icons/name {:color "#6a35ff"
:stroke 1.25
:size 24}]))
The only problem is that the parameter name
can't be used. I wonder if I could do it with a macro?
Found this from stackoverflow https://stackoverflow.com/questions/2966014/how-do-i-create-a-macro-to-define-two-functions-in-clojure
; given a function name, its args and body, create 2 versions:
; ie (double-it foo [] ) should create 2 functions: foo and foo*
(defmacro double-it
[fname args & body]
`(do (defn ~fname ~args ~@body)
(defn ~(symbol (str fname "*")) ~args ~@body)))
(double-it afunc [str] (println str))
(afunc* "asd")
(afunc "asd")
@U4YGF4NGM Wherein lies the limitation?
the stackoverflow you posted is different than what I thought you were talking about
let me be clear what I'm saying you can't do: you can't have a function or a macro which allows other namespaces to dynamically refer or require things for you.
there's a lot you could do but I'm going to cut to: I think your best bet is to require the icons and use a macro to generate the various functions you want to use
here's an example of what I mean: https://github.com/lilactown/helix/blob/master/src/helix/dom.cljc
this generates a bunch of macros (but could be functions) like input
, div
, etc. to cut down all the boilerplate
you can create a macro to generate the icon-plane-departure
fn in your original post and any other icons you need
the limitation you're working around is that a namespace needs to refer to anything that's going to be used in it, so that it's statically analyzable, so that the clojurescript and google closure compiler emits the correct code
this is different than Clojure, which includes the compiler with your program. ClojureScript does not, so it has to do everything ahead of time, which means we're restricted more on how dynamic we can be
This doens't work:
(defmacro tabler-icon-macro [name]
`(r/as-element
[:> ~(symbol (str "tabler-icons/" ~name)) ; <<<<<
{:color "#6a35ff"
:stroke 1.25
:size 24}]))
while this does work:
(defmacro tabler-icon-macro [name]
`(do
(prn ~name)
(r/as-element
[:> ~(symbol (str "tabler-icons/" "IconPlaneDeparture")) ; <<<<<
{:color "#6a35ff"
:stroke 1.25
:size 24}])))
Does someone know why?
The string printed for ~name
is IconPlaneDeparture
name
resolves to a symbol. A symbol that's not bound. It should be passed quoted or turned into a string beforehand.
Did anybody code a slack app / bot lately? How would you go about it? I have a small project and considered js but then I thought I use cljs if I have the chance. I'm thinking to basically use this https://github.com/slackapi/bolt-js-getting-started-app but use clojurescript
This doens't work:
(defmacro tabler-icon-macro [name]
`(r/as-element
[:> ~(symbol (str "tabler-icons/" ~name)) ; <<<<<
{:color "#6a35ff"
:stroke 1.25
:size 24}]))
while this does work:
(defmacro tabler-icon-macro [name]
`(do
(prn ~name)
(r/as-element
[:> ~(symbol (str "tabler-icons/" "IconPlaneDeparture")) ; <<<<<
{:color "#6a35ff"
:stroke 1.25
:size 24}])))
Does someone know why?
The string printed for ~name
is IconPlaneDeparture
Try it with name
instead of ~name
in the call to str
.
why do you want this to be a macro? I mean why do you do the r/as-element
? but even without just make it a function and call it with (tabler-icon tabler/IconPlaneDepature)
why write a macro only to skip passing in the tabler/
alias?
Ah yes, the first rule of Macro Club: Don’t use macros.
The idea was that I could generalize the usage of icons instead of creating an icon function for every icon that I use.
you don't have an icon function for every icon. you have one icon function and pass in the icon to use as an argument
(defn icon-plane-departure []
(r/as-element [tabler-icons/IconPlaneDeparture
{:color "#6a35ff"
:stroke 1.25
:size 24}]))
This is for n=1 icon. But I thought it would be cumbersome to have to write something like that for every icon I wanted to use.
(defn small-icon [the-icon-to-use]
(r/as-element [:> the-icon-to-use
{:color "#6a35ff"
:stroke 1.25
:size 24}]))
(small-icon tabler-icons/Thing)
(small-icon tabler-icons/ThatOtherIcon)
either :refer
them in the require or make the alias shorter. otherwise no but I also don't see a problem with that 😛
Okay Thank you. I think i have over engineered that one 😅 Defintely don't need a macro. But in theory would it be possible to do that part with a macro?
not really practically speaking. you can do it but it'll be much more clunky and annoying
Thank you anyways, you just saved me from diving deeper into the rabbit hole. Although now i know how to possibly use a macro another time 😄
I've been trying to help in this original thread: https://clojurians.slack.com/archives/C03S1L9DN/p1634658147275100 correct me if i'm wrong thheller
you can go with a macro that sets up a namespace with all the icons from the package. I wouldn't recommend doing that but you can.
ClojureScript master now has a new flag - :global-goog-object&array
- intentionally ugly name - to get the old behavior where a library could assume goog.object
or goog.array
would be present