Fork me on GitHub
#clojurescript
<
2017-03-03
>
sineer00:03:51

Any suggestion how I can do the equivalent of "import marioPNG from "./mario.png";" and use the webpack file-loader to decode that image file? I can load the data but I need it decoded in same format webpack file-loader...

shaun-mahood00:03:51

@olivergeorge: That repo really helped - seeing how you had to :require everything and not :import made a huge difference, and I finally got the quickstart translated to CLJS and working. In the course of getting to this I've had to reinstall Java, reinstall Node, learn a bunch about the Closure compiler, and learn how to test and compile Clojurescript with a patch. Thanks a ton!

lprefontaine00:03:05

Hi everyone, I need some ideas... I have a cljs app, trying to compile it with simple optimization. One of our namespaces is reported missing (JSC_MISSING...). The require of this namespace has been added to the top level namespace but for some reason the compiler still does not seem to detect it (it's working fine with figwheel however). The compiler never copies it to the 'out' folder before calling the optimization phase. It's referenced in 5 different namespaces. This namespace requires goog.string and alike. That's the only feature that sets it apart What am I missing ? Using 1.9.473 here...

emccue00:03:24

Well, see if goog.string is the problem

emccue00:03:36

Then see if it compiles with no optimizations

emccue00:03:21

Maybe it's a filesystem issue of some sort

darwin00:03:21

@lprefontaine not sure if this is exactly your issue, but I believe there was a subtle bug in :whitespace and I assume in :simple mode as well. the order of dependencies concatenated in generated file can be wrong under some circumstances. The :none and :advanced modes work properly.

lprefontaine00:03:54

Ok, will give it a try. Looks like it's related to the source file format. Did a test with Replete using copy&paste and a couple of lines did not pass the compilation in the REPL.

qqq00:03:03

Short Question: is it possible to throw an UNCATCHABLE EXCEPTION ? Long Question: I'm doing

(defmethod mutate 'todo/new-item [...]
  {:action
    (fn []
      (. js/console log "hit pre line")
     (assert false)
      (. js/console log "hit pre line")
)})
Now, when I press the new item button, I get: "hit pre line" I don't get "hit post line" and I don't get an exception So it seems like OM caught my exception, and then ignored it. Returning back to my question: is there a way to either (1) tell OM to NOT catch my exceptions OR (2) throw an UNCATCHABLE exception ?

anmonteiro00:03:37

@qqq not possible, but you can check the error you’re getting

anmonteiro00:03:48

it’ll be in the return value of om/transact!

qqq00:03:31

@anmonteiro : nice, thanks! I get the exception from om/transact! now

qqq00:03:46

however, is it possible to tell om/transact! to not catch it? I'd prefer cljs-dev tools catch it and show me the debugger

qqq00:03:56

when om/transact! catches it, I end up getting a bunch of js line numbers inated of cljs line numbers

lprefontaine00:03:32

I looked at the compiler output using the verbose flag. It says "Analyzing" for this specific file but it never compiles it... I re-created the file from a cat output to make sure no non-printable characters are present.... still no change,,,

anmonteiro00:03:49

not possible AFAIK, but you can probably rethrow it

qqq00:03:04

if I rethrow it, I get line where the rethrow happens, not the origiinal line right?

anmonteiro00:03:24

I don’t know, but since you get an instance of js/Error it’ll probably have the original stacktrace

anmonteiro00:03:38

that would be my assumption

qqq00:03:39

where is transact! efined? https://github.com/omcljs/om/search?utf8=%E2%9C%93&amp;q=transact%21 I don't mind modifying it as this is really important to me

qqq00:03:46

I will test out rethrow

anmonteiro00:03:50

also this would probably be a conversation more appropriate to have in #om

qqq00:03:02

@anmonteiro : got it all working; thanks for your help! the "om transact! returns exception" was the key part

lprefontaine01:03:30

Found it, they were still a couple of creepy characters hidden in the namespace o the source file. Hence the namespace hierarchy did not match the file path... 😬🔫

sudodoki08:03:33

question have anyone seen figwheel setup where app would be served not on localhost:3449/ but on localhost:3449/some-arbitrary-path-here? Would love someone giving me pointer. Also, this might be X-Y problem, so will talk about the problem I’m having: I’m using secretary and accountant (utilizing html5 history) for reagent SPA. when ran on localhost everything is ok, but once deployed to gh-pages of a project, it breaks because /login !== /some-path/login. I tried using (secretary/set-config! :prefix “some-path”) but it seems not to work for me.

sudodoki08:03:34

or should it be handled in :ring-handler? :thinking_face:

Aron09:03:26

anyone seen routing solutions where there is not a global config where you specify which route shows which components, but where the components themselves can decide if they want to appear for a certain path (route)? i am trying to avoid having to use something like react-router

jrychter09:03:37

@ashnur: I hate the term "routing" (I think it dates back to the PHP era) and I use something different, which works the way you describe. I have to write it up in a blog post, really.

jrychter09:03:34

Basically, I pass around a nav-state structure, which contains the URI split into "tokens". The structure contains a list of :consumed-tokens and :remaining-tokens. Every component only deals with (first (:remaining-tokens nav-state)), and when calling other components, calls consume-token, which simply takes one token from :remaining-tokens and places it onto :consumed-tokens. That way every component can have its local nav structure, independent of anything else, and it's also reusable: you can use the same component at several places in your application.

mobileink22:03:05

jrychter: interesting. can you elaborate a bit? it sounds like you eschew the traditional dispatcher fn, which takes a path and finds a component to call based on a dispatch table. you give dispatch authority to components, by adding a nav-state param to their signature. is that accurate? the dispatch table is still there, but it's implicit, wired into the components. sth like that?

jrychter13:03:05

@U0LGCREMU: yes, that's an accurate description. As a result, I can rearrange and reuse components at will, and the URI structure follows automatically and naturally.

jrychter09:03:10

I use this extensively in PartsBox (https://partsbox.io/).

jrychter09:03:28

This means that I have no global "routing table": as the nav-state structure is passed down the component tree, everybody consumes whatever they need, and things just happen.

jrychter09:03:27

For building links, I have a bunch of utility functions, some build relative links based on the current nav-state, and some (very rare) build global links.

Aron09:03:01

i don't follow completely

Aron09:03:02

if you consume, how you add a new components that appears on the same path?

jrychter09:03:57

The render function for your component (that exists at say "/main/comp1") calls (comp2 (consume-token nav-state)). This means that if the URL was really "/main/comp1/something", your comp2 will get a nav-state with :consumed-tokens ["main" "comp1"] :remaining-tokens ["something"], so it will only deal with "something".

Aron09:03:45

what if there is another component that would also need "something"

jrychter09:03:48

But if it needs to construct a full URL to something, it still can.

jrychter09:03:24

Every nav path points to only one component, not sure how you'd like it to be otherwise. Of course, that component can render whatever it wants (including several other components with no knowledge of navigation).

Aron09:03:07

well, for me nav paths don't point to components, rather they define a context in which components can choose to do whatever they want. I do parse it into parts to be able to generate new paths but it does not modify the path so it allows other components to act on it

Aron09:03:44

i just see no reason to be destructive.

jrychter09:03:43

Can you use the same component (with its local navigation) in two different places in your app? I think any approach that doesn't follow the "one path -> one component" is fundamentally problematic if you want reuse.

jrychter09:03:07

Also, there is nothing "destructive" about what I described. It's a pure functional approach.

jrychter09:03:24

Your app tree becomes a function of your nav path, this simplifies a lot of things.

Aron09:03:36

i see no reason why i couldn't. instead of writing if route matches this, i write if route matches this or this. Similarly, using the same component multiple times, i just include it multiple times into the parent view.

Aron09:03:14

i am not saying I know better, usually when i am doing something else than others, i am missing something, i just don't know what, in this case

jrychter09:03:22

I am not going to argue — I have a nice and simple solution which works very well and allows me to move components around and reuse them without modifying any global routing table. Whatever works for you 🙂

rauh09:03:19

I'm doing something similar to you, jrychter, but take it even a step further with the simplicity: I'm only ever 2 levels deep with the tokens (namespace + name), and then for some routes some "parameters". Haven't needed more levels with my app (over >30 routes).

Aron11:03:43

@jrychter i wasn't trying to argue, i was asking if you see something obviously wrong with i am saying. I am not questioning the validity of your setup, obviously, i am here to learn, mostly, not to put up my views against other's views 🙂

Aron11:03:25

and thanks for what you've told me because it is really good to know that i am not the only one who has issues with global routing tables

jrychter12:03:13

Well, I don't think it's "wrong", just that it's more complicated that it should be, and has certain disadvantages (like not being able to easily reuse components in a different part of the app). I can't see any advantages, only complexity and disadvantages.

jrychter12:03:02

I am trying to build apps where the entire component tree is a function of the URI and the app-state atom, and where components can be rearranged at will (e.g. uri structure will follow). I know there is one drawback: this doesn't work if you don't control the URI structure, e.g. if somebody tells you that particular URIs must map to particular places in the app.

Aron12:03:46

@jrychter interestingly, my own experience was that this made things simpler, not complicated. but i am guessing that we just simply don't understand each other's architecture clearly, that's why we both are a bit confused about it 🙂

hkjels12:03:36

How do I retrieve the doc-string of a defn?

hkjels12:03:48

(meta some-fn) => nil

moxaj12:03:05

@hkjels (meta #'some-fn), assuming some-fn is a var

hkjels13:03:45

@moxaj ahh, great.. Thanks!

jimmy14:03:03

hi guys, is there anyway we can convert clj->js but we still want to keep the namespace in keyword ?

dnolen14:03:30

@nxqd conversion between clj/js value is around two protocols - so yes

jimmy14:03:22

@dnolen Thanks for the answer. I stumbled upon the same issue being posted here ? http://dev.clojure.org/jira/browse/CLJS-536 . But it seems extending the protocol is the solution for now

dnolen14:03:56

yeah we’re not going to change the default behavior now

dnolen14:03:59

pointless breakage

dnolen14:03:33

so extending the protocol is the answer and probably always will be

sineer15:03:09

I want to give a shout out to @doglooksgood amazing parinfer mode for emacs https://github.com/DogLooksGood/parinfer-mode

victorvoid16:03:57

@dnolen do you can help me? 😕

shaun-mahood16:03:37

@victorvoid: Probably worth asking in #re-frame, there are some interactions between the 2 libraries that can make a difference to how well it works. https://github.com/yogthos/memory-hole also uses Secretary and re-frame so might give you some ideas.

shaun-mahood17:03:35

I've got an error I don't understand related to require vs import for Google Closure dependencies - it's not actually necessary for me to understand or fix it, I'd just like to understand why it's happening this way. https://github.com/smahood/openlayers-cljs/blob/master/openlayers-clojurescript/src/quickstart/core.cljs works fine, but https://gist.github.com/smahood/464eaa974247ae3f382f012ed0afc082 gives me an error message. From my (poor) understanding, if the dependency is a class then I should be using import, but this doesn't seem to work that way in this case. I get similar results if I change any of the other requires to import statements. Any ideas?

jr17:03:23

this is cljs right?

jr17:03:29

import is for java classes

jr17:03:02

so not really relevant to cljs

jr17:03:09

unless you're writing a macro

shaun-mahood17:03:13

@jr: Yes, cljs - using a google closure library though, and import is recommended for classes in https://clojurescript.org/reference/google-closure-library - and I think the code in question is a class and namespace based on the docs at https://openlayers.org/en/latest/apidoc/ol.source.OSM.html and the interop usage of (ol.source.OSM.). Very, very possible I'm wrong about something fundamental here though.

jr17:03:57

> This is only for when you would like to refer directly to a class which is also a namespace

jr17:03:35

that appears to be the case

shaun-mahood17:03:11

@jr: Ok, so it looks like import should work there, right?

shaun-mahood17:03:48

Ok at least I didn't misunderstand that part, thanks :)

thheller19:03:09

@shaun-mahood if you import something you can use the short name for it

thheller19:03:29

that is pretty much the only difference to require

shaun-mahood19:03:09

@thheller: Oh that makes sense, thanks!

binliu4clojure19:03:06

question about using map

binliu4clojure19:03:13

if i have the following

binliu4clojure19:03:19

(defn render-welcome-message-content[msg] ([:dev.welcome-message-content msg])) `

binliu4clojure19:03:43

(defn render-welcome-message [] [:div.welcome-message-container (map render-welcome-message-content welcome-message-1 welcome-message-2)])

binliu4clojure19:03:49

what did i do wrong

tanzoniteblack19:03:34

@binliu4clojure ([:dev.welcome-message-content msg]) means "create a vector and then call it as a function"; you probably have an extra set of parens around that

tanzoniteblack19:03:02

(that's the body of render-welcome-message-content)

binliu4clojure19:03:21

oh should be div, but still get error

binliu4clojure19:03:27

not quite following..

binliu4clojure19:03:12

what i want is [div.welcome-message-container [:div.content msg1] [:div.content msg2]]

binliu4clojure19:03:53

so i define a function output [:div.content msg], msg as argument, and use map

tanzoniteblack19:03:19

your first problem has nothing to do with render-welcome-message, but render-welcome-message-content; you have an extraneous set of parentheses in render-welcome-message-content

tanzoniteblack19:03:49

(defn render-welcome-message-content [msg]
  ([:dev.welcome-message-content msg]))
should probably be
(defn render-welcome-message-content [msg]
  [:dev.welcome-message-content msg])

binliu4clojure19:03:14

got it!! Thanks!

binliu4clojure19:03:44

but now it seems it take all my msgs , each letter as an element and out put them each letter one line...

tanzoniteblack19:03:25

and if you want something that looks like [:div.welcome-message-container [:div.welcome-message-content "msg1"] [:div.welcome-message-content "msg2"]]; you probably want to use

(into [:div.welcome-message-container] (map render-welcome-message-content welcome-message-1 welcome-message-2))

binliu4clojure19:03:36

warnings is each child in an array or iterator should have a unique key

binliu4clojure19:03:54

(defonce welcome-message-2 "Sign in with your GitHub account")

binliu4clojure19:03:10

how to represent an object in cljs?

binliu4clojure19:03:30

or make the function think msg2 is one element instead of a lot of letters?

tanzoniteblack19:03:20

oh! sorry, (into [:div.welcome-message-container] (map render-welcome-message-content welcome-message-1 welcome-message-2)) should be (into [:div.welcome-message-container] (map render-welcome-message-content [welcome-message-1 welcome-message-2])), or something similar

tanzoniteblack19:03:49

by using a string directly as an argument to map like was originally there, it's calling the function on each character in the string

binliu4clojure19:03:06

Ah yes. putting [] around msg1 and msg2 do the trick

metametadata20:03:15

@shaun-mahood I guess it should be (:import [ol.source OSM]) in order to call constructor like (def my-source (OSM.))

metametadata21:03:40

but yeah, I can't explain the machinery, just following the rules 🙂

shaun-mahood21:03:40

@metametadata: Fantastic, that works - apparently I'm not smart enough to understand the docs right the first time. Thanks!

rgdelato21:03:38

Is there any way to write the equivalent of a JS debugger; statement? (js/debugger) throws a ReferenceError

hlolli21:03:19

trying to do some clojurescript namespace hacking (don't worry, this is for my eyes only). I'm attemting to make cljs vesion of Mikkera's pull macro in clojure. Basically merge the symbol interns into a new namaepace. This creates an infinite loop, maybe an stupid attemt and I guess most here would talk my out of this idea.

(defn pull [into-namespace namespace]
  (let [into-map (get-in @env/*compiler* [:cljs.analyzer/namespaces
                                          into-namespace
                                          :defs])
        replace-map (get-in @env/*compiler*
                            [:cljs.analyzer/namespaces namespace :defs])
        merged-map (merge into-map replace-map)]
    (swap! env/*compiler* assoc-in [:cljs.analyzer/namespaces
                                    into-namespace
                                    :defs] merged-map)))

rgdelato21:03:53

It looks like I can use (js/eval "debugger") and then step out in the debugger to get to the line in the sourcemap, but that's not amazing...

anmonteiro21:03:37

@rgdelato there’s cljs.core/js-debugger

rgdelato22:03:24

@anmonteiro awesome, thank you! That works! For future reference, where would I go to look up that kind of thing?

anmonteiro22:03:58

I think this is a pretty good resource http://cljs.github.io/api/

anmonteiro22:03:06

they’re directly mapped from the source

borkdude22:03:51

I've never used Google Closure with a non-cljs project, but I just want to know this: do you still need to provide externs if you use packages with one of the supported module formats or are they entirely different concerns?

spinningtopsofdoom22:03:33

I'm playing around with loading node modules to ClojureScript and so far it seems like you still need externs.

isak22:03:57

afaik it is for foreign libs, not needed when you see JS written like this file: https://github.com/cognitect/transit-js/blob/master/src/com/cognitect/transit.js