Fork me on GitHub
#clojurescript
<
2017-12-07
>
thedavidmeister02:12:04

is there a reason why :foreign-libs stopped supporting URLs at some point?

thedavidmeister02:12:10

or is this a regression?

qqq02:12:22

how does https://cljs.github.io/api/cljs.core/locking work ? (notice the macro basically does nothing) is it because cljs is single threaded ?

danielcompton02:12:45

@qqq yeah it's just for compatibility with Clojure

mfikes03:12:51

@thedavidmeister Sounds like a regression. https://clojurescript.org/reference/compiler-options#foreign-libs indicates "URL to the library. This can be either local path or remote url to the dependency file". If you can create a minimal repro: https://clojurescript.org/community/reporting-issues

thedavidmeister03:12:33

@mfikes uh, ok, i'll add it to my list of things to do >.<

thedavidmeister03:12:39

thanks for helping

thedavidmeister03:12:58

for me, i just drop any URL in and it complains about not finding the file on the local file system

thedavidmeister03:12:08

it spits out an absolute fs path in the error

thedavidmeister03:12:33

java.io.FileNotFoundException: /Users/davidmeister/hoplon-ckeditor5-test/https:/cdn.ckeditor.com/ckeditor5/1.0.0-alpha.2/balloon/ckeditor.js (No such file or directory)

mfikes03:12:35

@thedavidmeister Does your URL start off with https:/cdn.ckeditor.com? Perhaps it needs another slash?

thedavidmeister03:12:06

{:foreign-libs [{:file ""
                  :provides ["ckeditor.lib"]}]})

thedavidmeister03:12:23

java.io.FileNotFoundException: /Users/davidmeister/hoplon-ckeditor5-test/https:/cdn.ckeditor.com/ckeditor5/1.0.0-alpha.2/balloon/ckeditor.js (No such file or directory)
   clojure.lang.ExceptionInfo: /Users/davidmeister/hoplon-ckeditor5-test/https:/cdn.ckeditor.com/ckeditor5/1.0.0-alpha.2/balloon/ckeditor.js (No such file or directory)
    from: :boot-cljs

thedavidmeister03:12:32

the irony is that i'm getting this error while trying to make a minimum repro for ckeditor

thedavidmeister03:12:41

so i need a minimum repro for my minimum repro >.<

sova-soars-the-sora04:12:46

Can I check for equality with keywords using (= :keyword/name (first ?data)) ?

reefersleep07:12:20

Yeah. I do that all the time @sova

reefersleep07:12:00

Equality in Clojure is pretty good

reefersleep07:12:26

Usable on deep structures, too

kardan07:12:17

How do I set a nested value of a js object? I see I can use goog.object/getValueByKeys to get a value. But I can’t find a assoc-in. Do I miss something?

kardan08:12:31

@fbielejec will do, thanks!

qqq08:12:40

In plain JS, when you deref a promise, it bundles up "rest of the function" as a callback, and registers it as an event handler right? In CLJS->JS, are there any CLJS constructs that auto become callback handlers? [I'm trying to understand what blocks of cljs code are "atomic" vs "spread across multiple callbacks"]

turkkam08:12:35

Can i emit JavaScript code during ClojureScript macro expansion phase? Currently i'm using js/eval to evaluate the generated code. Seems like there could be another way 🙂.

thheller08:12:27

@qqq deref is not async, it is just a function call.

qqq09:12:27

@thheller: I was under the impression that exec "pauses" if the value is not available yet.

qqq09:12:40

If this it not achieved via wrapping "rest of function" in a callback -- then how so ?

thheller09:12:00

no such thing as blocking in JS so there is no blocking deref

qqq09:12:37

So if we deref a promise, and no value is available yet, what happens?

thheller09:12:41

can’t deref a promise either in JS

qqq10:12:56

@thheller: upon some further reading, I completely misunderstood js promises; thanks for the clarifications

cmal10:12:03

Hi, I have a problem when defining a higher-order function in form-3 reagent component's reagent-render function. Code follows:

cmal10:12:05

When page is loaded, only "@@@ run me!!!" and "@@@@annc-dividend" printed out, the two doall in annc-dividend did not run. But when page did hot reload, all 4 prn printed out. I am confused. Can anyone help me with this? Thanks a lot.

cmal10:12:18

Found the answer in

cmal10:12:34

If, however, this render function returns another function - ie. it is a Form-2 outer function returning the inner function - then Reagent knows to replace the Component's render function with the newly returned inner function forever thereafter. So the outer will have been called once but, from that point forward, the inner function will be used for all further rendering. In fact, Reagent will instantly call the inner function after the outer returns it, because Reagent wants a first rendering (hiccup) for the component.

mfikes12:12:40

@kardan If the JavaScript object already has the nested structure, I would goog.object/getValueByKeys to get the desired nested object and then goog.object/set to set the value on it. (I would avoid aset as it is for arrays.)

kardan12:12:23

@mfikes thanks for the direction!

kardan12:12:34

Taking baby steps in the ClojureScript world

vemv14:12:13

this prints false. is there any workaround?

vemv14:12:45

using an atom is not an alternative, because unrelated 'threads' would see values from each other

dnolen14:12:18

@vemv you cannot have bindings work across async calls, just not possible

tbaldridge20:12:45

@dnolen that' works in Clojure, bindings are propagated across gos

tbaldridge20:12:37

We use Var.getThreadBindingFrame to get all the var bindings and store them for when the go starts. Of course that doesn't work in CLJS where bindings aren't stored in a central location.

dnolen21:12:32

@U07TDTQNL ah that must have been fixed later no? I didn’t realize someone got around to that

tbaldridge21:12:08

I've heard that gos don't support bindings for some time though, so I'm not sure where that started.

dnolen21:12:40

@U07TDTQNL hrm I’m thought people had examples that didn’t work - but ok!

tbaldridge21:12:24

with-redefs doesn't work (and never will) at least in the way people seem to expect.

tbaldridge21:12:31

So perhaps thats what the examples are using?

dnolen21:12:34

yes, I think this was from people complaining from a testing/mocking context

dnolen14:12:35

won’t work in Clojure either, since you don’t know what thread will run what async block when

vemv14:12:19

I was kinda preparing for this answer, a viable alternative seems to be explicit argument passing

rainmote16:12:39

Hi, I want to add date picker, but I don’t found satisfactory project. I want to date range picker on page, and convert date string to timestamp, eg: 2017-12-01 01:01:59 to 1512061319. Is there a good project recommendation?😀

rainmote04:12:20

@turkkam @jsa-aerial thanks, I did not find the relevant information about minutes and seconds, I hope enter 2017-12-08 12:12:12 in input text, and I use re-frame and semantic-ui.

turkkam07:12:44

So you want to parse 2017-12-08 12:12:12 as date ? You can just (.parse js/Date "2017-12-08 12:12:12")

deg19:12:07

is it legal to have a .cljs and .cljc file with the same name, directory and namespace?

noisesmith19:12:11

iirc require would always pick up one and ignore the other - easy enough to find out though

mfikes20:12:59

@deg Yes. The rules are that .cljs will be loaded in preference to .cljc when requiring a runtime namespace. (Let me see if that is documented.)

mfikes20:12:59

This is not really documentation but it reflects the order tried:

cljs.user=> (require 'x)
No such namespace: x, could not locate x.cljs, x.cljc, or JavaScript source providing "x"

mfikes20:12:13

There is a pending ticket for Clojure to do the same: https://dev.clojure.org/jira/browse/CLJ-1797

mfikes20:12:14

And, if you are requiring a macros namespace, the order tried is .clj followed by .cljc

mfikes20:12:23

I'd suggest submitting a PR to https://clojurescript.org documenting this.

mfikes20:12:57

I like the rule: If you just learned something that is not documented, well, you know what the right thing is to do 🙂

Alex Miller (Clojure team)20:12:40

prob good to doc at https://clojure.org/reference/reader#_reader_conditionals too. I swear I have done this in the past but don’t see it there

josh20:12:47

Is it feasible to use Clojurescript without React or other Facebook libraries? Or is Clojurescript tightly tied to React/Immutable?

chris20:12:10

it's not coupled to them at all

chris20:12:33

in no way is it tied to a facebook library outside of the various react wrappers

josh20:12:54

thanks, so there aren't limitations or frustrations with just writing vanilla.js using clojurescript?

josh20:12:17

(I see a wrapper for mithril.js so maybe I'll tinker with that a bit...)

noisesmith20:12:17

I think react is particularly attractive because it works well with idiomatic clojure coding styles, but I’ve definitely used jquery and d3 via interop

noisesmith20:12:24

I don’t see why any js lib would be significantly harder to use in cljs than js - (though if it’s doing preprocessing for syntax or something that’s not going to blend so nicely for obvious reasons)

josh21:12:40

Thanks, I don't like Facebook as a company and don't want to get involved in their ecosystem in any way. React has been my main blocker with checking out clojurescript. If I can avoid FB, then I'm interested in trying it. I'll try the tutorial and Moria (mithril wrapper) this weekend.

gklijs11:12:46

You can also get a long way without using a framework, just using a mix of javascript interop with google closure.

deg21:12:02

@mfikes Thanks. I'm running busy the next few days, but will try to submit a PR if no one beats me to it.

mfikes21:12:12

@josh FWIW, ClojureScript isn’t even tied to the browser. You can think of it as a language that compiles to JavaScript. It is used for example to create programs that run in Node.js, or drive hybrid mobile apps.

josh21:12:14

Great, thanks. I'm trying a tutorial now.

noisesmith21:12:17

@josh this cljs binding to Vue.js might be interesting - I haven’t tried it though

josh21:12:30

even better... we use Vue on our site 🙂

noisesmith21:12:59

yeah - I started by seeing what was a viable react alternative and Vue looked like the winner there, and only then looked for bindings / wrappers

noisesmith21:12:34

because I’d rather work with an imperfect binding to a solid lib (and proceed with interop as needed) rather than an extensive binding to something inferior

noisesmith21:12:12

but of course starting cljs dev as a new thing, with a lib that is funky to use from cljs… might not be the best introductory experience

New To Clojure21:12:56

It's unusual that there's no CLJS wrapper for Angular 2. Only the blog post with example how to write a simple app.