Fork me on GitHub
#clojurescript
<
2017-06-07
>
chrisdavies01:06:46

If anyone here uses re-frame, I'm curious what router they use with it (and how)?

shaun-mahood01:06:02

@chrisdavies: There will probably be more responses in the #re-frame channel, but in the docs there are a few different examples https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md - Memory hole uses secretary and should be a good example.

chrisdavies01:06:56

Thanks, shaun!

fadrian03:06:59

I have a relatively simple RESTful web service to write. If I had my way, I'd write the service in Clojure and be done with it. The only fly in the ointment is that I work for a shop which is enamored of node.js. No worries, I say, I'll just use Clojurescript and target node.js. Not only does it let me use a decent language, but it obfuscates the code for free! So I set out to write my RESTful web service in Clojurescript. Most of the examples of this on the web punt into express (from the node.js ecosystem) to do routing. However, when you scratch deeper than the simple examples on the web, you find that express' interface is riddled with state and requires mutation of data structures to transfer information between levels of middleware. So my first question is whether or not anyone has done anything like this? If so, how did they bend express' interface to their will? Otherwise, is there something equivalent to ring and compojure for clojurescript? Ideas on how else to approach this are welcome...

fadrian04:06:33

@shaun-mahood: Thanks for that. I'll check it out.

pradyumna05:06:34

@adamvh Mmm. When I see the tutorials on on.next the parent components query is union of child components. It receives the child component data as props and then passes them down to child component. I am confused. Its kind of duplication.

dnolen07:06:58

@pradyumna there’s an #om channel by the way 🙂

defclass09:06:30

Hi all, I am very new in cljs and js, and I just encounter a strange problem below :

(defn get-img [file]
  (when (is-img? file)
    (let [url (or js/window.URL
                 js/window.webkitURL)
         file-url (.createObjectURL url file)
         img (js/Image.)]
     (set! (.-src img) file-url)
     img)))

upload-file is #object[File [object File]]

(.-width (get-img upload-file)) => 0

(def x (get-img upload-file))
(.-width x)  => 810
Maybe I’m thinking about this problem incorrectly. thanks .

darwin09:06:05

@michael.wong (my theory) try to set onload handler on that img with some debug logging to see when it fires, I guess you are querying width on img instance which is not fully loaded, by coincidence second time it works due to timing

defclass09:06:25

@darwin thanks, let me have a try

defclass09:06:58

Hi @darwin, it was the case , thanks again simple_smile

pesterhazy09:06:32

A thought - wouldn't be great if figwheel reloaded its configuration on SIGHUP?

honzabrecka12:06:16

Can self-hosted cljs handle deps.cljs?

honzabrecka12:06:33

Because in lumo I can’t require any of cljsjs package.

weavejester13:06:18

Does anyone happen to know of a simple websocket library for ClojureScript?

weavejester15:06:17

I took a look at Sente; it seems overkill for my case, and has a very weird API

weavejester15:06:55

If the API was more idiomatic I’d consider it, though.

seantempesta09:06:46

Yeah. I’m not thrilled with the API either and have been reluctantly using it.

weavejester13:06:50

The only one I’ve found that seems simple is Chord, but I don’t like the duplex channel.

pesterhazy14:06:56

I just use (js/Websocket.) directly

pesterhazy14:06:48

not feeling the need for a wrapper

pesterhazy14:06:49

roughly,

(let [websocket (js/WebSocket. websocket-url)]
  (doto websocket
    (aset "onopen" (fn []
                     (prn [:onopen])))
    (aset "onmessage" (fn [event]
                        (did-receive-message (.-data event))))
    (aset "onerror" (fn [event]
                      (prn [:onerror])
                      (.close websocket)))
    (aset "onclose" (fn []
                      (prn [:onclose])))))

roman01la14:06:55

What is the alternative?

pesterhazy14:06:23

what are you trying to do @roman01la? I wouldn't expect hash to be portable across platforms - or even restarts of the jvm

roman01la14:06:55

@dominicm yes, looking into it right now. thanks

roman01la14:06:47

@pesterhazy yeah, we’ve just discussed hashing issues between cljs and clj as well as between JVM instances

roman01la14:06:39

if the problem is caused only by numbers I guess recursive walk to serialize numbers and escape strings would work fine for my usecase

roman01la14:06:33

or converting a map into sorted-map and serializing it before performing hashing

roman01la14:06:17

though not sure if serialization would produce the same order in cljs and clj

rauh14:06:36

If you just need a fingerprint: Why not transit it, and use the md5 of that? Not sure what you're trying to do though.

roman01la14:06:32

@rauh I want a simple solution, more or less efficient and it should not add KBs to cljs bundle

dominicm14:06:49

Sounds exactly what hasch is designed for really

rauh15:06:40

I see, I figured maybe you're already using transit. And md5 can be replaced by hash if that's enough

roman01la16:06:38

That’s super dirty hack, but should be fine for my use case cljs

;; Retrieve 64-bit IEEE754 representation of JavaScript's Number type
(defn- double->ieee [f]
  (-> f js/Float64Array.of (gobj/get "buffer") js/Uint32Array. js/Array.from (aget 1)))

;; A hack to hash JavaScript's Number type as Java's Double
(extend-type js/Number
  IHash
  (-hash [n]
    (double->ieee n)))
on clj side all numbers should be doubles

domkm17:06:40

Is there a way to globally set *warn-on-infer* to true?

thheller17:06:27

@domkm no, it is not ready for that. too many incorrect warnings

domkm17:06:52

I see, thanks

dnolen17:06:28

it’s intentionally file local since it applies to any non-inferrable interop form

dnolen17:06:33

that would affect a lot of code

john17:06:59

If you're trying to avoid lots of set!s on vars cluttering up the top of your ns and you wanted to manage those settings on an app level, you could set! those and other vars in a particular function in some util namespace, say setup-vars! or set-defaults!. Then call setup-vars! for every namespace where you want that behavior. Then you could also have that function set! different settings based on different flags you specify, like :dev, or :advanced or ':warn-level 5,' etc.

domkm17:06:50

Has this proposed solution (https://github.com/clojure/clojurescript/wiki/Singleton-Pattern-Externs-Inference-Support) been implemented? I ask because it doesn't seem to remove Object warnings for me.

dnolen18:06:16

@domkm not implemented

captainlexington18:06:08

It differentiates between actions that we might want to undo and actions we won't want to, but it doesn't seem to differentiate between state we want undone and state we won't

captainlexington18:06:48

In re-frame I tend to store both user data and UI state in app-db, but I'll almost certainly only want to be able to step back user-data changes, even if UI changes occur after

captainlexington18:06:06

If I understand re-frame-undo correctly, the option to undo will still be available, but it will undo the UI changes as well

captainlexington18:06:10

For instance, if I were writing an app for creating jogging routes before going on a run, I would be able to add waypoints and to pan and zoom the map. I would store both the waypoints and the pan and zoom state of the map in app-db, but I would only want undo to affect changes made to waypoints, leaving the zoom and pan options unchanged

captainlexington19:06:12

Ugh, I thought of how to implement it in the library, looked around the source, figured out how to do a PR, and then saw a description of how to do it in the flippin' Readme. facepalm

weavejester20:06:43

Is there a way of finding out more about a ClojureScript analysis error?

shaun-mahood20:06:43

@captainlexington: There's an active and helpful #re-frame channel for the next time you run into a re-frame specific issue. Glad this one was easy to figure out 🙂

captainlexington20:06:01

@shaun-mahood Thanks! I keep forgetting there's more channels than just the ones in the sidebar

sb20:06:00

Hi, how could I implement this in Clojurescript?

google.visualization.events.addListener(chart, 'ready', function() {
            console.log(chart.getChart().getImageURI());
                document.getElementById('png').innerHTML = '<a href="' + chart.getChart().getImageURI() + '">Printable version</a>';
        });

sb20:06:55

is that correct?

sb20:06:07

(.addListener js/google.visualization.events chart "ready" (fn [] (.log js/console (.getImageURI js/chart))))

weavejester21:06:24

It looks like you’re missing out a few things.

weavejester21:06:51

(-> chart .getChart .getImageURI)

weavejester21:06:24

(set! (.-innerHTML (document/getElementById "png")) "<a href=...>")

sb07:06:47

weavejester: thanks! sorry I just see now your message

qqq21:06:19

I'm still having problem with name mangling. Is there a better way t odo this rewrite so it works with opt-advanced ?

;; amazon.Login.setClientId ('foobar')
                        (let [a (oget js/document "amazon")
                              l (oget a "Login")
                              sci (oget l "setClientId")]
                          (ocall sci "foobar"))

darwin22:06:59

@qqq why don’t you simply write (gcall "document.amazon.Login.setClientId" "foobar")? that would generate the same code

darwin22:06:09

and I don’t know why this does not work in advanced mode, it should as long as this amazon stuff is not subject of google closure compiler optimization