Fork me on GitHub
#beginners
<
2019-06-17
>
katzdan02: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

benisrood08:06:58

^ what Lennart means:

(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))))))

benisrood08:06:29

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

benisrood08:06:29

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

vale02:06:19

why the double parens around the native module function calls?

katzdan04:06:26

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

shin07:06:25

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

sveri08:06:39

@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.

d.eltzner09:06:34

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?

d.eltzner09:06:59

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

carladrago09:06:33

Don't know if this is helpful Schmoho, but I was experiencing a similar problem and realised I needed to namespace the REPL. (from https://www.braveclojure.com/basic-emacs/) >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.

d.eltzner09:06:21

Yup! Thanks a lot.

shin09:06:13

@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

sveri09:06:44

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"?

shin09:06:01

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

sveri11:06:07

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

k.i.o11: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.

dpsutton12:06:49

@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?

credulous16:06:51

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.

credulous16:06:15

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

lilactown16:06:37

how are you starting the REPL?

credulous16:06:57

My deps.edn looks like

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

 :deps {
... various dependencies
}
 }

credulous16:06:06

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.

credulous16:06:30

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

lilactown16:06:52

src/ is not on your classpath

credulous16:06:21

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

credulous16:06:51

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

lilactown16:06:57

where are you running the REPL start command?

credulous16:06:01

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

lilactown16:06:41

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

user=> (require 'alexandria.templates)

lilactown16:06:20

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

credulous16:06:15

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

lilactown16:06:48

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

credulous16:06:06

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

papachan19:06:04

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

andy.fingerhut19:06:15

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

andy.fingerhut19:06:39

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.

andy.fingerhut19:06:37

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

theron.bair23:06:26

anyone around?

theron.bair23:06:29

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

theron.bair23:06:35

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

ericcervin23:06:48

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

theron.bair23:06:10

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

theron.bair23:06:29

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

theron.bair23:06:06

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.)

theron.bair23:06:12

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.

theron.bair23:06:20

(note: this is via the REPL)

ericcervin23: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 .

theron.bair23:06:15

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

theron.bair23:06:19

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.

theron.bair23:06:57

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

theron.bair23:06:34

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.

ericcervin23: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?

theron.bair23:06:18

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.

theron.bair23:06:44

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

theron.bair23:06:33

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.

theron.bair23:06:58

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

theron.bair23:06:33

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

noisesmith23:06:16

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

noisesmith23:06:28

if I understand the situation you are describing correctly

theron.bair23:06:43

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

seancorfield23:06:13

@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.

noisesmith23:06:32

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)

seancorfield23:06:14

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.

theron.bair23:06:15

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

noisesmith23:06:38

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

theron.bair23:06:02

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

noisesmith23:06:03

@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

noisesmith23:06:27

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

seancorfield23:06:12

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).

theron.bair23:06:55

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

seancorfield23:06:12

(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?)

noisesmith23:06:42

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

theron.bair23:06:53

(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)

noisesmith23:06:09

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

seancorfield23:06:33

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.