Fork me on GitHub
#clojurescript
<
2020-02-18
>
rberger07:02:14

In chromex Is there a way to add a css file to the content-script in the manifest.edn? Its possible to do in the standard chrome-extension with something like:

"content_scripts": [
   {
      "matches":    [""],
      "css":        ["fix.css"],
      "js":         ["script.js"]
   }
],
I've manually updated the manifest json like:
"content_scripts":
 [{"css": ["re-frame-modal.css"],
     "js":
   ["out/content-script.js", "out/cljs-runtime/goog.debug.error.js",
    "out/cljs-runtime/goog.dom.nodetype.js",
 
And that works But I've tried a few things in manifest edn like:
:content-scripts {:css ["re-frame-modal.css"]}
But that generates slightly malformed manifest.json
"content_scripts":
 {"css":["re-frame-modal.css"],
  "js":
  ["out/content-script.js", "out/cljs-runtime/goog.debug.error.js",
   "out/cljs-runtime/goog.dom.nodetype.js",
 
The chrome extension import doesn't like that

Old account13:02:22

have you seen such datastructure in ClojureScript : #object[DOMException NotFoundError: Requested device not found]

p-himik13:02:24

It's just how CLJS prints some JS objects, in this case DOMException.

Old account13:02:48

problem is that I am sending this via EDB to CLJ server and can not read there. I guess I have to register some tagged literal reader here

Old account13:02:21

So #object[whatever] would read as a string?

Old account13:02:28

what would you suggest?

p-himik13:02:01

Wait. Why do you send this over the wire in the first place?

Old account13:02:31

I save logs in the server side - for later

p-himik13:02:10

Serialize the exception properly, not just with prn, and then send the serialized data over.

p-himik13:02:38

Perhaps you should serialize all exceptions in the same manner that doesn't remove any information from them.

p-himik13:02:00

The original string that you posted does not contain any useful information at all.

Old account13:02:24

how would you serialize the exception?

p-himik13:02:45

There's clojure.stacktrace, but you should definitely ask about it in #clojure - I think there were some better options that give you the data itself and allow you to control the serialization process.

p-himik13:02:38

I just realized that in CLJS the exceptions are very different from CLJ. I'd probably use something like https://www.npmjs.com/package/serialize-error or JSON.stringify(err, Object.getOwnPropertyNames(err)).

paul a14:02:25

unfortunately, the shadow-cljs built-in macro for slurping files at compile time isn't good enough, because i need to read bytes (not UTF-8) from my file. i've defined a CLJC namespace containing my slurp-bytes macro, but now it doesn't seem straight forward to require that CLJC code in my CLJS code; instead, i'm getting this pretty much inscrutable error message, without a stack trace: Error in phase :compilation

paul a14:02:18

i guess i'll take this to #shadow-cljs

denik18:02:47

happy to announce a powerful data -> UI resolver I've been working on for a while: https://www.reddit.com/r/Clojure/comments/f5ur6a/root_recursive_ui_resolution/

👍 12
matheusashton22:02:43

Hello! 🙂 I’m using clojurescript with reagent and figwheel (https://github.com/bhauman/lein-figwheel) I’m trying to add routing to my application with secretary, using dispatch! it’s everything working fine but I wanted to react to the URL, so I’ve added a ring_handler option and created a proper handler:

(ns pets-manager.server
  (:require
   [clojure.string :refer [starts-with?]]
   [ring.middleware.resource :refer [wrap-resource]]))

(defn- wrap-default-index [next-handler]
  (fn [request]
    (next-handler
     (if (or (starts-with? (:uri request) "/css/")  ;; default directory layout after doing
             (starts-with? (:uri request) "/js/"))  ;; `lein new figwheel my-app`
       request
       (assoc request :uri "/index.html")))))  ;; wrap-resource will find index.html for us

(def handler
  (-> (fn [_] {:status 404 :body "static asset not found"})
      (wrap-resource "public")
      wrap-default-index))
but when I try to access any routing (like /pets) I get the 404 error (static asset not found) can you spot what am I doing wrong?

matheusashton22:02:00

here is the repo in case you wanted to check it out: https://github.com/ashton/pet-manager

aisamu01:02:57

:resource-paths ["public"] means that index.html is available at "/index.html" (wrap-resource "public") will make the server look for assets on "public/..." , not on "/...." (wrap-resource ".") does the trick, but that looks like a weird setup. Is this from a template?

matheusashton14:02:23

actually I have a public folder at the same level of my project.clj and inside it there is the index.html that loads my builded script

aisamu14:02:15

Is it on the repo? If so, that's what I've tested against

matheusashton14:02:32

yes, it is on the repo

matheusashton14:02:19

hmm, it worked, but I didn’t understand exactly why

aisamu14:02:49

The server looks for resources on the classpath, not on project folders. (wrap-resource "public") says that the html resources are inside a "public" folder on the classpath But index.html is available on the "root" of the classpath, per :resource-paths ["public"]

aisamu14:02:53

:resource-paths ["public"] adds the contents of public to the classpath, not "public" itself - just like :source-paths ["src"] adds the contents of "src", but not the folder itself.

matheusashton15:02:09

Oh, I’ve got it 🙂 thanks!

🎉 4
matheusashton15:02:07

Now I just have to look how to initialize secretary with the browsers URL on the page load

☝️ 4
matheusashton15:02:14

thank you very much

matheusashton15:02:21

hahaha! do you speak portuguese?

😉 4
matheusashton20:02:39

Hi, can I bother you with one more question?

matheusashton18:02:46

I’m trying to make a router work with an re-frame application, but I’m not sure yet how do I make something like react-router with clojurescript, anyone that can help with? I tried to use secretary and now I’ve changed to re-frame-routing that uses bidi and pushy under the hood, but I still couldn’t make it work The problem is that I couldn’t sync secretary’s dispatch! with browser’s url, I was able to route the application internally but the route doesn’t reflect on the browser URL, and if I try to change the URL manually (like a href’s link) the page reloads

aisamu19:02:41

I'll open by saying that I'm not too fond of react-router's model - redux-first-router is a much nicer experience if you're already using redux. In the same vein, I'd look into [kee-frame](https://github.com/ingesolvoll/kee-frame), which puts the url in the "driving seat" so to speak. For url and history sync, common libs are [pushy](https://github.com/kibu-australia/pushy) and/or [accountant](https://github.com/venantius/accountant). You have to plug your router into them, but that's usually straightforward. It might also be useful to check SPA re-frame templates, as they probably have ironed out most of the kinks you are running into!

matheusashton02:02:45

Thanks for the help again, I’ve already saw some people recomending kee-frame, but sine I’ve just started using clojurescript I rather not to use so much higher level abstractions. Since re-frame is a well known and stablished framework I’ve wanted to learn how it works before using some abstraction on top of it

matheusashton02:02:10

That said, I’ll look into pushy and accountant, thank you 😄

👍 4