Fork me on GitHub
Dan Katz02:06:00

Hi all, I'm new to Clojurescript. I'm trying to invoke a function in a java based react native module. All native modules return promises in react native and I'm trying to get the ClojureScript bit right but I get a message from Node during compilation that "UnhandledPromiseRejectionWarning: Unhandled promise rejection..." . My code looks like this and to the bast of my understanding - nothing is missing: (when platform/android? (try (-> ((.-isAvailable RNTextDirection)) ;1st neative module function (.then (fn [value] (when value (-> ((.-isRTL RNTextDirection) text) ;2nd neative module function (.then (fn [value] ( (or value (right-to-left-text? text) (assoc :rtl? true)))) (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true)))))))) (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true))))) (catch js/Object err ( (right-to-left-text? text) (assoc :rtl? true))))))Can anyone help me understand what's missing here? Thanks!

Lennart Buit06:06:03

If you enclose your code in triple backticks it gets monospaced. Alternatively you can press the plus button, and select text/code to even get highlighting in your favorite language

Lennart Buit06:06:03

with backtick I mean: `, which are impossible to escape correctly in slack


^ what Lennart means:

(when platform/android?
        ((.-isAvailable RNTextDirection)) ;1st neative module function
          (fn [value]
            (when value
                ((.-isRTL RNTextDirection) text)  ;2nd neative module function
                (.then (fn [value] ( (or value (right-to-left-text? text) (assoc :rtl? true))))
                (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true))))))))
        (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true)))))
      (catch js/Object err ( (right-to-left-text? text) (assoc :rtl? true))))))


In slack, if you want someone to read a code sample, ALWAYS wrap in `


on the first line before and after the last line of your code


why the double parens around the native module function calls?

Dan Katz04:06:26

Thank @vale, I missed that. Checking the code without the double prthsis.


Hello, does anybody know how I would run a command every x minutes using the morse library for telegram bots?


@shin I dont know about morse or telegram bots, but if you use clojure you could use a scheduling library that runs a function every x minutes.


Hello. Can someone give me some hints on profiling with Leiningen and Cider? Cider is customized to use lein on jack-in. However, when the REL starts it's in a barren user-ns, unlike lein repl which starts into a default profile which has stuff like clojure.repl pre-loaded. This however is confusing to me too, since my project.clj only specifies profile :uberjar and in my .lein-folder in home there is not profiles.clj. So ... what's going on here?


Ah okay, I guess what happens is lein repl boots into the main-ns specified in project.clj (duh) but jack-in doesn't.


Don't know if this is helpful Schmoho, but I was experiencing a similar problem and realised I needed to namespace the REPL. (from >In the buffer of the file you want to namespace, use C-c M-n M-n. This key binding sets the namespace to the namespace listed at the top of your current file.


Yup! Thanks a lot.


@sveri I took a look at chime, but my problem is mainly that a handler is running that checks incoming messages etc. and I'm not sure where to put my scheduler function so it will actually get executed


I am not sure what you mean exactly? If you look at the documentation you see for instance this:

(chime-at [(-> 2 t/seconds t/from-now)
           (-> 4 t/seconds t/from-now)]
          (fn [time]
            (println "Chiming at" time)))
chime-at takes a vec defining when and the intervall and another function which is the function to run and what in your case is the "handler"?

🙂 4

Sorry, I meant that morse is using a handler for the telegram bot, didn't make that clear


I still dont understand the problem, maybe you could post some example code?

Ivan Koz11:06:24

Is there a way to disable head retention optimization for seq's? I remember there was an option but can't find it.


@d.eltzner that is a bug then. You should have the repl utils in the user namespace and CIDER should honor the lein default namespace when specified. Can you raise an issue on github?


Hi. I’m having trouble getting my workflow going with CLI / deps.edn. I use fireplace on vim. When I start a repl using clj, I can connect to it fine. If I create a src/user.clj file, I can eval the (ns user) and eval forms in the file from the editor.


However when I go to one of my actual source files I can’t eval anything, even (+ 1 2) etc.


how are you starting the REPL?


My deps.edn looks like

{:aliases { :run {:main-opts [ "-m" "alexandria.core" ] } }
 :paths ["src/clj" "resources" ]

 :deps {
... various dependencies


The error I get is

Execution error (FileNotFoundException) at user/eval31472 (REPL:1).
Could not locate alexandria/templates__init.class, alexandria/templates.clj or alexandria/templates.cljc on classpath.


that is when I try to eval within the file src/alexandria/templates.clj


src/ is not on your classpath


Sorry, the file is actually src/clj/alexanria/templates.clj


I’ve started the repl both with clj and clj -A:run


where are you running the REPL start command?


Project directory, parent of src. The user.clj file that I can eval within is at src/clj/user.clj


as a test, try starting the REPL at the project directory:

user=> (require 'alexandria.templates)


if the above doesn’t work, then we know it’s not a Fireplace issue. if it does work, then it might be something to ask in #vim


OK, thanks, it must be a fireplace issue. I haven’t seen it when using lein which is why I blamed my transition to CLI


yeah sorry. I’d help more, but I am not a vim or Fireplace user


I’ve also been evaluating clojurescript code just fine when I start the repl with shadow-cljs


Is it still a good practice to use *base-url* vars name with * ?


If the Vars are dynamic, it is still a common convention to name them with * or "earmuffs"


If a Var is not dynamic (i.e. declared with the metadata ^:dynamic or the equivalent ^{:dynamic true}), then the Clojure compiler warns you if you have earmuffs on the name.


That is not an error, but a warning, I believe intended to prevent you from accidentally using such earmuffed names for non-dynamic Vars.

🙌 4
👍 4

anyone around?


who would like to rewire a total n00b's brain who's having trouble figuring out Luminus? (spoiler: "me")


I have a feeling it's due to the fact that I am seriously misunderstanding something fundamental.

Eric Ervin23:06:48

You have Mr. Sotnikov's book about web development in Clojure?


I do not, no. No books as yet, working with what I can Googlize only so far.


(probably that will be remediated at some semi-distant point in the future, but, $$$)


Here's my issue/problem: I'm attempting to create a "something" on the "Clojure" side of a Luminus project, and cause it to be visible on the "Clojurescript" side of it. (This mental model of what it looks like internally probably isn't even wrong, but that demonstrates where I'm at, basically.)


For some reason I settled on the idea that I should create an atom containing that "something" (basically a string), but that doesn't appear to suffice.


(note: this is via the REPL)

Eric Ervin23:06:46

What are you trying to make? I've seen a lot of cases where total nOObs are told to skip the framework and build their service with Ring/Compojure/Liberator .


... a mess. It's just a test project, for to make learnings glorious Clojure etc. etc.


My next stop after putzing around with this and figuring out how it works is a toy monitoring thing that I can extract data from services on the underlying OS and dump to some snazzy page that's all Javascripty and everything.


... so I'm attempting to invoke to get a "something", which I can then glue into an output somewhere.


Being as that's not available on the Clojurescript side, I'm needing to figure out a way to slurp stuff from "underneath", somehow, and then pass it out so it can be rendered. This is the sort of thing that would be trivial for someone with more experience than I, but you get experience by flailing around until you figure it out, etc.

Eric Ervin23:06:59

Hopefully a second opinion will come along, but it seems to me that you're trying to do too much at once as a total nOOb. Have you gotten to "Hello HTTP request" in your browser?


I imagine the second opinion will be much the same as that one. The yak-shaving pathway to get to Luminus was that I initially tried to use straight Reagent, but couldn't get any sort of shell library to work underneath.


(which, in retrospect, was obvious: it's not a ClojureScript thing)


And I've gotten the projects to do their "hello world" bits, and tweaked them that way, but the problem is getting stuff from "outside" the Clojure universe somewhere "inside" it so I can use them.


It seems like the sort of thing that should be simple-ish.


... so it probably is, in some sense.


@theron.bair the common options there are xhr (discreet requests) and websockets (a continuous stream of data)


if I understand the situation you are describing correctly


... so there's a piece missing that I need to glue into this thing to have it shuffle stuff back and forth?


@theron.bair Since cljs runs in the browser and Clojure runs on the server, you need the cljs client to make calls to an API of some sort on the server side. The client would ask the server to do "something". The server would do that thing and respond with data. The client would take that data and display it/update the display.


right, there's libraries for both (xhr is usable on its own via interop, I've found the sente library improves the situation of bare websockets significantly)


And if the server portion is publicly accessible in any way, you'll need to think about security/authentication because otherwise "anyone" can call that API and run whatever code you've made it run.


To be specific: my initial test is just this: run /bin/date, capture string, pass to "something".


right, that doesn't work at all via a browser


@seancorfield well, yes, of course; this is just playing. 😁


@theron.bair I think xhr is the easiest way to pull data into an already rendered page without a new page load, the normal setup is you have a POST endpoint that receives the request and returns JSON encoded data in the body of the response


but really any intro web-dev book that's reasonably recent will cover all of this


Yeah, if you're going to use Luminus, I strongly recommend buying the book. There's a third edition in preparation so the ebook is discounted (and will get updates as the book evolves).


Certainly not married to Luminus, if there's a Better Way To Do It(tm).


(I assume the 3rd ed book will be substantially complete from day zero since it's an evolution of the 2nd ed, but maybe @yogthos might be able to chime in?)


everything I'm describing is just details of what you'd do in luminus (or any other set of libs that isn't totally alien), this stuff is pretty standardized


(nota bene: I'm not by trade a web-dev, if that's not obvious; I do cloud infrastructure stuff, and looking to broaden my horizons a bit)

🌅 4

yeah, even more reason to get a good web-dev book


Writing a simple server-side rendered web app with Clojure is pretty straightforward. Writing an SPA with cljs on the front end and clj on the backend is a lot more to learn all at once. Diving into a big template like Luminus is going to increase the learning curve even more.