Fork me on GitHub
#clojurescript
<
2019-11-22
>
ikitommi06:11:34

@zelark failed because of coercion? you had defined the :id as integer? and "b" was a string.

alekszelark07:11:48

@ikitommi yes it is, but I want to handle the coercion exception. I realized that coercion happens automatically, while the documentation says you have to manually do it.

alekszelark07:11:51

in reitit.frontend/match-by-path

ikitommi07:11:08

the docs might not be in sync, sorry for that. with reitit.core, matching path and coercion are two separate steps. with reitit.frontend there are things bundle to make it… easy.

alekszelark07:11:25

Now I got it. But is there a way to catch the exception from match-by-path?

ikitommi07:11:45

It should never thow.

ikitommi07:11:45

unless uri is nil, which should never be the case I believe.

alekszelark07:11:34

Hm, what if user specifies a wrong url: items/12a? I’d rather want to show 404 instead of an error.

ikitommi07:11:35

oh, the reitit.core/match-by-path never throws, only the coercion in reitit.frontend/match-by-path. Just try-catch` it?

alekszelark07:11:04

Yeah, but the problem is that I don’t understand where I need to catch it.

alekszelark07:11:15

I’ll show you the code

alekszelark07:11:45

(def router
  (reitit.frontend/router
    routes
    {:conflicts nil
     :compile reitit.coercion/compile-request-coercers}))

(defn on-navigate [new-match]
  (if new-match
    (rf/dispatch [:set-current-route new-match])
    (rf/dispatch [:page-not-found])))

(defn init-routes! []
  (js/console.log "initializing routes") ;; TODO: get rid of it.
  (reitit.frontend.easy/start!
    router
    on-navigate
    {:use-fragment true}))

ikitommi07:11:53

I would suggest writing an issue to reitit to provide a way to handle the exception in an easy way.

alekszelark07:11:10

Ok, I’ll do

alekszelark07:11:19

Thank you for supporting

ikitommi07:11:29

currently, the match-by-path is called before calling your on-navigate so no easy way to do that: https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/history.cljs#L123

ikitommi07:11:05

… so you would need to rewrite a lot of code to get that.

ikitommi07:11:15

btw, there is #reitit to get help on reitit 🙂

alekszelark07:11:22

yeah, thanks, initially I didn’t think it related to reitit, just an exception I cannot catch for some reason, that’s why I used this channel.

dabrazhe11:11:52

I've discovered promises in Clojurescript : ). I understand that the promise value cannot escape the promise chain, ie the chain won't return the value, but yet another promise. what is the best practice in Clojurescript for passing on the value, eg to another function? someone suggested assigning it atom, but it's plainly changing the state; does not this beat the premise of immutable data?

p-himik11:11:31

> what is the best practice in Clojurescript for passing on the value, eg to another function? Just passing it as a parameter? I'm not sure what you're asking.

mccraigmccraig13:11:05

just chain handlers... either using the .then fn directly, or with a lib like funcool/promesa which gives you some nice binding sugar too - https://cljdoc.org/d/funcool/promesa/4.0.2/doc/user-guide#promise-composition

dabrazhe19:11:13

@U2FRKM4TW Say in the (-main) function I fetch an api call that returns a promise. Now, to process the resutlt I either have to send it to another function as a value. Which means I am branching execution to another function everytime I call an API. If I want to continue to process the result in (-main) I either need to send it to a channel and take! from it later on, or to reset! an atom and deref it later in the main. I am looking for best practice, since i've just learned about promieses.

p-himik19:11:21

@U96LS78UV I see. Yeah, just do what mccraigmccraig said. reset! and deref will not work because JS has only 1 thread. And even if you employ asynchronous code, there's still no guarantee by itself that deref will be executed after reset!.

birdspider17:11:07

does or how does shadow-cljs or cljs in general handle polyfills/transpilation (for :browser) ? i.e. js/Promise in IE11, or is it delegated to a bundler (webpack)

birdspider17:11:09

@lilactown just tried shadow-cljs sample project (https://github.com/shadow-cljs/quickstart-browser) in release build and Promises are missing in IE11, even with :compiler-options {:output-feature-set :es3}

thheller17:11:03

@birdspider polyfills depend on where they are used. did you use them in CLJS code or some included JS code?

birdspider17:11:06

i used js/Promise in the src/starter/browser.cljs of the sample project, which compiles to main.js which is the sole js in the index.html

thheller17:11:26

then you need to set :compiler-options {:rewrite-polyfills true} as well

birdspider18:11:21

@thheller ah I see, it a cljs flag, I was looking at the shadow-cljs doc, thxs

thheller18:11:51

polyfills handling is a bit sketchy. could definitely be cleaner 😛

birdspider18:11:02

@thheller btw, this should be update in the doc @lilactown posted, because currently the safest default and supports most browsers in active use (including IE10+) seems not to be correct without the :rewrite-polyfills

lilactown18:11:20

In the past I've ended up using something like http://polyfill.io to detect the browser being used and ship a minimal polyfill

lilactown18:11:51

it comes with its own issues though

birdspider18:11:23

@lilactown oh thats cool, didn't know that site

birdspider18:11:58

@lilactown does it react on User-Agent ?

danielbraun20:11:19

I'm getting Execution error (ClassNotFoundException) at http://java.net.URLClassLoader/findClass (URLClassLoader.java:381). com.google.common.collect.Stream when requiring reagent, does anyone know what's up?

thheller20:11:50

@dabra usually a dependency conflict on guava

danielbraun20:11:39

now I have to figure out what Guava is

danielbraun20:11:58

@thheller that solved it, on to the next reagent error

danielbraun20:11:02

can't find variable .......$react_dom$index

danielbraun20:11:01

(require 'reagent.core) (reagent.core/render [:h1 "Hello World"] (.-body js/document)) undefined is not an object (evaluating 'reagent.core.render.call')

thheller20:11:35

what do you use to compile?

danielbraun20:11:29

just starting a REPL with clj -m cljs.main

thheller20:11:12

looks like you have :npm-deps enabled?

danielbraun20:11:06

I don't, but I don't like this direction really, guessing what the error is, I don't think it's a good investment of my time

thheller20:11:02

try shadow-cljs 😉

danielbraun20:11:35

i'm done dealing with implicit errors

thheller20:11:36

I'm sure its a simple error though but I haven't used the default tools in a long time so I can't offer any help really

danielbraun20:11:40

why is software broken all the time? it's shocking

johnj21:11:10

what options are you pasing to cljs.main?

danielbraun21:11:52

thanks for the help, gonna leave it for now. I'll try again later

Nima G23:11:49

don't give up 🤡