Fork me on GitHub
#clojurescript
<
2018-11-28
>
henrik07:11:22

I need to expose a function at the very top-level in a script. I.e., I need to generate something like,

var aFunction = function (params) {…
It’s for a tool that requires it. I don’t think it evaluates the file from top to bottom, it just goes and looks for that exact function in the file.

henrik07:11:39

Is this possible to do with CLJS?

orestis07:11:41

Like, greps the file? That’s weird...

henrik07:11:01

I’m not sure how it’s actually doing it, but given a file where the function is just bog-standard exported, it just goes aFunction is not a function.

henrik07:11:32

I.e., (defn ^:export aFunction) is clearly not fancy enough for it.

orestis07:11:48

Like, you can declare a top level function a few ways in JS. If it does have a to be a weird thing like that I’d just write a JS function wrapper.

henrik07:11:17

Oh, right. How would you make one of those?

orestis07:11:21

The export thing puts the function inside the current namespace, so if it has to be a global thing, I’m not sure if it is possible.

henrik07:11:47

Do you have a separate file that requires the CLJS-JS file?

orestis07:11:46

Sorry, I meant write a .js file with the function as the tool expects it, and the function body just calls your exported CLJS function. You will need to figure out how to include both files of course.

orestis07:11:37

I vaguely remember a figwheel conf (no idea if it’s a cljsbuild one) that allows you to prepend/append comments and code to your final build...

orestis07:11:05

Perhaps? It will be a the top level of the file but I think JS will hoist the global Vars anyway so it should work?

henrik07:11:23

I’ll give it a shot

henrik07:11:25

Thank you!

orestis07:11:34

If all else fails you could just append something to your final output out of band :)

henrik07:11:04

I think I found the shadow-cljs equivalent. I set the target to be :node-library, and added :exports-var silly-lib/aFunction, and it sure seems to work.

chrisetheridge10:11:33

has anyone been having trouble with Secretary (and dispatching) and the new cljs version?

orestis11:11:02

@biscuitpants it has been forked and now maintained under clj-commons: https://github.com/clj-commons/secretary

achikin15:11:49

File: ...
failed to require macro-ns "clojure.core.strint", it was required by "..."
FileNotFoundException: Could not locate clojure/core/strint__init.class or clojure/core/strint.clj on classpath.

achikin15:11:00

Where did strint go in clojurescript?

danielstockton15:11:32

I don't think it ever made it into clojure either

achikin15:11:27

Oh, I had core.incubator in dependencies...

enforser16:11:58

Does anybody know of a library for cljs to decompress LZ4? I know I could get this by including a npm dependency - is that feature still considered experimental?

Whiskas17:11:12

DId someone here already have to use Pushy + Bidi for routing?

Whiskas17:11:30

I’m willing to know how to make Pushy to work with figwheel in this situation

Whiskas17:11:43

so i can go to localhost/somepage

Whiskas17:11:55

and figwheel will actually return the index.html for me

Whiskas17:11:38

I would need something like this: (routes (ANY “*” [] (layout/render “index.html”)))

mfikes18:11:53

@trailcapital If the LZ4 library you have in mind works via :npm-deps, it should be fine to consume the library that way.

enforser18:11:41

ah, great. It should work that way, so that's perfect. Thanks!

borkdude19:11:24

into-array accepts an optional type argument for compatibility with clojure. But how does one call it in a way that’s compatible with clojure and clojurescript? e.g. you need a reader conditional here, because JS doesn’t know what Integer/TYPE is:

(->>
         (into []
               (map #(u/parse-int %))
               (str/split-lines input))
         (into-array #?(:clj Integer/TYPE)))

borkdude19:11:49

so I don’t see how the optional arg is useful for compatibility

dpsutton19:11:56

is there a way to check if a transient hash set has been persisted yet? i'd like to have an assert while i'm tracking down a bug but not sure how to check for that

dnolen19:11:08

@dpsutton what do you need beyond checking the type?

dnolen19:11:15

if it’s transient it’s not persisted

dpsutton19:11:45

ah i was thinking there was a flag that was set, ie, a transienthashset could be persisted but its type remained as transienthashset. thanks david

dnolen19:11:07

@dpsutton ah yeah, wouldn’t be functional with that kind of api, since that would mean banging on a flag in place

dpsutton19:11:12

but now i see the source 🙂

dpsutton20:11:43

(deftype TransientHashMap [^:mutable ^boolean edit this edit flag seems to be the flag i was worried about

dnolen20:11:11

@dpsutton that’s not for you to use

dpsutton20:11:42

it's what's causing me issues right now. i've got to track down why i have a persisted transient

dpsutton20:11:50

i just need to throw an assertion and track down the logic

dnolen20:11:52

whenever you see ^:mutable on a deftype knee jerk reaction should be “don’t touch that”

dnolen20:11:00

if you do, then good luck

dnolen20:11:08

chances are you broke something

jaawerth04:11:07

...now I want to do it and see what breaks 😈

dpsutton20:11:28

well just someone called persistent! on this transient somewhere

dpsutton20:11:51

and as far as i can tell, this happens but they immediately assoc in a new fresh transient set. so i'm confused where this invariant does not hold is all

dnolen20:11:38

could use a debugger and set a breakpoint on persistent! no?

dpsutton20:11:16

i think that's a new angle for me to approach. thanks

dnolen20:11:59

could also monkey patch persistent! with your own that dupes functionality then watches for some case and logs that