clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Gleb Posobin 2020-10-30T01:40:54.398200Z

Content scripts do get updated for me without reload, with shadow cljs.

Gleb Posobin 2020-10-30T01:41:31.398400Z

The only problem is when you navigate to another page, chrome loads the initial content script the extension started with.

nezaj 2020-10-30T05:29:43.399600Z

Does someone here have a working set-up of vim-fireplace + Piggieback for clojurescript? Spent a couple hours trying to get this to work with no luck. Would love some help! I can get a cljs repl working via

lein repl
(cider.piggieback/cljs-repl (cljs.repl.node/repl-env)) 
But can't get vim-fireplace to connect to it. Similarly in vim if I run :Piggieback (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)) I'll see To quit, type: :cljs/quit which makes me think it worked but trying to execute a form gives me an error like
Unexpected error (ExceptionInfo) compiling at (REPL:1).
No such namespace: guestbook.core, could not locate guestbook/core.cljs, guestbook/core.
cljc, or JavaScript source providing "guestbook.core" in file <cljs repl>
I also tried using weasel. I have a function to fire-up a browser repl
(defn repl-env  []
  (cljs.repl/repl
   (weasel.repl.websocket/repl-env :ip  "0.0.0.0" :port 9001)))
After which I do lein repl and (repl-env) to start a weasel server. My logic in core.cljs for connecting to it when opening my app in the browser
(when-not (weasel.repl/alive?)
  (weasel.repl/connect "<ws://localhost:9001>"))
With this I have a cljs repl as well. Sending commands like (.log js/console "Hello World") works and I can see the log in my chrome inspector. However still cannot get vim-fireplace/piggieback to connect to it.

victorb 2020-10-30T09:40:55.400600Z

Hey! Yeah, I did have vim-fireplace + clojurescript working with piggieback before. Now I'm using conjure instead of vim-fireplace, but when I was using vim-fireplace + figwheel, I found this guide to be the most helpful: https://figwheel.org/docs/vim.html Are you using figwheel/shadow-cljs or something else?

nezaj 2020-10-30T18:37:10.437Z

@victorbjelkholm429 I'm using neither figwheel or shadow-cljs (using lein-cljsbuild atm for building cljs resources). I've been working through Web Development with Clojure (from Pragmatic bookshelf) when I hit this snag with with vim-fireplace/cljs. I do see a chapter or so later in the book there is some set up for shadow-cljs and from looking at some online articles may find luck there

nezaj 2020-10-30T18:37:42.437200Z

Thanks for this figwheel resource too šŸ™‚ Will report back on progress

ā¤ļø 1
miikka 2020-10-30T11:36:15.402600Z

tried to upgrade from ClojureScript 1.10.520 to 1.10.773 and our code doesn't work anymore in IE11 with advanced optimizations šŸ˜ž Closure is generating for (const d in a) and IE says SCRIPT1053: Const must be initialized.

miikka 2020-10-30T11:37:29.403500Z

Previous versions generated var d; for (d in a) which was fine

miikka 2020-10-30T11:39:18.403700Z

maybe :language-out will help...

miikka 2020-10-30T11:41:30.404100Z

right! :language-out :es5 solves the problem

Calum Boal 2020-10-30T11:59:17.405300Z

Hey, so i'm learning re-frame and trying to make a subscription which depends on two pieces of data from the database. For this im trying to use two subscriptions, but i get an error that the second arg should be the subscription function. How do i do this?

Calum Boal 2020-10-30T11:59:21.405600Z

(rf/reg-sub
 :active-server
 :&lt;- [:active-server-id]
 :&lt;- [:servers]
 (fn [active-server-id servers _]
   (first (filter #(= active-server-id (:_id %1)) servers))))

Calum Boal 2020-10-30T12:01:06.406200Z

Ah figured it out. For reference it needs to be this:

(rf/reg-sub
 :active-server
 :&lt;- [:active-server-id]
 :&lt;- [:servers]
 (fn [[active-server-id servers] _]
   (first (filter #(= active-server-id (:_id %1)) servers))))

Calum Boal 2020-10-30T12:57:15.406700Z

If i call a component within another componenet, will it still be treated as a component and rerender when dereffed values change?

Calum Boal 2020-10-30T12:58:24.407500Z

Because right now my nested components which deref things aren't being rerendered when the values in app-db change

Calum Boal 2020-10-30T12:59:24.408Z

(defn server-page []
  [:section.section&gt;div.container&gt;div.content
   (when-let [server @(rf/subscribe [:active-server])]
     (server-widget server server-clients-partial))])

(defn server-widget [server partial]
  [:div.card.bg-light {:style {:margin-bottom "2em"}}
   [:div.card-header.container-fluid
    [:div.row.w-100
     [:div.col-md-8
      [:h5.card-title (str "Server: " (:public-ip server))]
      [:h6.card-subtitle (str "Pubkey: "(asset/interface-pubkey server))]
      [:h6.card-subtitle (str "Allowed IPs: " (asset/interface-allowed-ips server))]]
     [:div.col
      [:button.btn.btn-primary.float-right "Generate Config"]]]]
   [:div.card-body.container-fluid
    [:div.row.w-100
    (peers-table server)]
    (partial server)
    ]])

(defn peers-table [server]
  (when-let [server-peers @(rf/subscribe [:server-peers server])]
    [:table.table.bg-light
     [:thead.thead-dark
      [:tr
       [:th {:scope "col"} "Pubkey"]
       [:th {:scope "col"} "Peer IP"]
       [:th {:scope "col"} "State"]
     [:th {:scope "col"} "Action"]]
      ]
     [:tbody
    (for [peer server-peers]
      [:tr
       [:td (asset/interface-pubkey peer)]
       [:td (asset/interface-allowed-ips peer)]
       [:td (asset/interface-state peer)]
       [:td
        [:button.btn.btn-primary {:on-click (fn [e]
                                              (.preventDefault e)
                                             (rf/dispatch [:unlink-assets peer server]))} "Remove"]]])

    ]]
   ))

(defn available-clients-table [server]
  (when-let [available-clients @(rf/subscribe [:available-clients])]
    [:table.table.bg-light
     [:thead.thead-dark
      [:th {:scope "col"} "Pubkey"]
      [:th {:scope "col"} "LAN IP"]
      [:th {:scope "col"} "Action"]
      ]
     [:tbody
      (for [client available-clients]
        [:tr
         [:td (asset/interface-pubkey client)]
         [:td (:lan-ip client)]
         [:td
          [:button.btn.btn-primary {:on-click (fn [e]
                                                (.preventDefault e )
                                                (rf/dispatch [:link-assets client server]))} "Add"]]
         ])
      ]]
    ))

Calum Boal 2020-10-30T13:00:16.408600Z

Basically when there's a change, available-clients-table and peers-table doesn't re-render until i refresh the page

p-himik 2020-10-30T13:29:58.408800Z

use [...] instead of (...) when working with components.

Calum Boal 2020-10-30T13:36:57.409300Z

Okay, done that, not solved the issue though šŸ˜ž

Calum Boal 2020-10-30T13:38:13.409500Z

Can post my subs if thhat helps

p-himik 2020-10-30T13:40:14.409700Z

Sure.

Calum Boal 2020-10-30T13:41:28.410100Z

Done, thanks for your help

p-himik 2020-10-30T13:42:21.410300Z

You mean, you fixed the issue?

p-himik 2020-10-30T13:42:41.410500Z

Ah, I see. Should've posted them in the thread.

p-himik 2020-10-30T13:43:51.410700Z

I can't see anything obviously wrong. At this point, unless someone else sees something, I need a proper minimal reproducible example.

Calum Boal 2020-10-30T13:43:58.410900Z

Nah not fixed the issue, and i thought the thread window might be too small. I can move them

p-himik 2020-10-30T13:44:32.411100Z

Better move them, yeah. The thread can be expanded to the full width.

Calum Boal 2020-10-30T13:45:20.411400Z

(rf/reg-sub
 :assets
 (fn [db _]
   (:assets db)))

(rf/reg-sub
 :active-server-id
 (fn [db _]
   (:active-server-id db)))

(rf/reg-sub
 :servers
 :&lt;- [:assets]
 (fn [assets _]
   (filter asset/server? assets)))

(rf/reg-sub
 :clients
 :&lt;- [:assets]
 (fn [assets _]
   (filter asset/client? assets)))

(rf/reg-sub
 :active-server
 :&lt;- [:active-server-id]
 :&lt;- [:servers]
 (fn [[active-server-id servers] _]
   (first (filter #(= active-server-id (:_id %1)) servers))))

(rf/reg-sub
 :available-clients
 :&lt;- [:clients]
 (fn [clients _]
   (filter #(=(count (:peers %1)) 0) clients)))

(rf/reg-sub
 :server-peers
 :&lt;- [:clients]
 (fn [clients [_ server]]
   (filter #(asset/has-peer? server %1) clients)))

Calum Boal 2020-10-30T13:48:17.411800Z

If i linked all the code would that help? If that's too much work to look through then no worries

p-himik 2020-10-30T13:49:23.412Z

Just create a small GitHub repo that I can clone and then run with a single command.

Calum Boal 2020-10-30T13:50:30.412200Z

Okay will try add some data seeding

Calum Boal 2020-10-30T14:24:51.412600Z

Here you go

Calum Boal 2020-10-30T14:24:51.412800Z

https://github.com/Cgboal/wire-runner

Calum Boal 2020-10-30T14:25:00.413100Z

You'll need mongo db but it'll seed itself

Calum Boal 2020-10-30T14:25:15.413300Z

docker run --name=WirerunnerMongo -v /var/lib/WirerunnerMongo:/data/db -p 27017:27017 -d mongo

Calum Boal 2020-10-30T14:25:32.413500Z

then just lein run and lein figwheel

Calum Boal 2020-10-30T14:26:28.413700Z

Go onto the web app, click add peer, select one from the available clients, it adds on the backend, the app-db updates, but the tables don't get re-rendered

p-himik 2020-10-30T14:34:43.413900Z

Well, that's not exactly minimal. :) But either way, I cannot run MongoDB: "Error: error checking path "/var/lib/WirerunnerMongo": stat /var/lib/WirerunnerMongo: no such file or directory" I'm using podman instead of docker, but that shouldn't matter.

Calum Boal 2020-10-30T14:35:25.414100Z

You can get rid of that argument if you like, it's just for container persistence

Calum Boal 2020-10-30T14:36:30.414300Z

Which you wont need, just pasted the docker cmd i used to start it

p-himik 2020-10-30T14:39:14.414800Z

Don't get me wrong - I want to help, but I really don't want to figure out how to run your project that's very far from a minimal reproducible example. Now I'm getting HTTP 404.

Calum Boal 2020-10-30T14:39:57.415500Z

On http://127.0.0.1:3000/ ?

p-himik 2020-10-30T14:40:42.415900Z

Figwheel: Starting server at <http://0.0.0.0:3449>

Calum Boal 2020-10-30T14:41:16.416100Z

Did you do lein run, if so, it's 127.0.0.1:3000

p-himik 2020-10-30T14:41:54.416500Z

OK, that seems to work.

Calum Boal 2020-10-30T14:42:25.417200Z

Nice one, thank you for taking the time to help

p-himik 2020-10-30T14:43:17.418Z

There's a bunch of JS errors. Potentially, then can be the ones that cause your issues. Have you tried fixing them?

Calum Boal 2020-10-30T14:44:57.419800Z

Only ones i was getting was Warning: Each child in a list should have a unique "key" prop.

Calum Boal 2020-10-30T14:45:34.420300Z

You mean that?

p-himik 2020-10-30T14:45:56.421Z

And &lt;th&gt; cannot appear as a child of &lt;thead&gt;.

Markus Str 2020-10-30T14:46:20.421600Z

hey guys, I'm observing some strange behavior. It seems there is some bugs importing a namespace with :as vs :refer. I have a clojurescript REPL running with #cursive and I'm testing out the new #malli lib (which looks awesome)

(ns scify.spectest
  (:require
    [malli.core :as m]
  [clojure.walk :refer [postwalk prewalk keywordize-keys]]
))
When I do as above it cannot find m and the linter puts it as grey (unused); also the REPL says Use of undeclared Var scify.spectest/m BUT m/validate is found as an object (?) Then if i do
[malli.core :refer [validate]]
It can find validate Also when I put malli.core into the REPL, it finds it It seems that I don't understand namespaces, but I'd assume that malli.core and m become equivalent once I do malli.core :as m (at least that works for most imports) Anybody know what I'm doing wrong? It's very confusing

Calum Boal 2020-10-30T14:48:46.421700Z

Fixed that in one place but missed the other, done that now, not affecting it, will look at the warning

hipster coder 2020-10-30T14:51:25.422700Z

quick questionā€¦ is there a CLJS way to run code on the server or the client? if I wanted to distribute some computation over a group of users/clients?

hipster coder 2020-10-30T14:51:44.423500Z

I remember reading about Clojure being able to do something like that

hipster coder 2020-10-30T14:52:05.424100Z

I am using the actor model, for distributed computing

dpsutton 2020-10-30T14:52:23.424500Z

if i'm reading you right, you're trying to use a var called m as if this is an object which contains functions. that's not the case. it's just introducing an alias so it can understand things like m/validate it knows that m is an alias for malli.core. There is no "thing" called m, its just a context to understand symbols

šŸ‘ 2
Calum Boal 2020-10-30T14:55:46.424700Z

Docs say the warning just pertains to performance of updates

Markus Str 2020-10-30T14:56:14.424900Z

mhh interesting. I thought it would be something like a reference

p-himik 2020-10-30T14:58:04.425500Z

Not sure what docs you're looking at, but that's not correct.

p-himik 2020-10-30T14:58:27.425700Z

Ah, wait - I'm probably mixing it up with index keys.

Calum Boal 2020-10-30T15:08:23.427600Z

Fixed the keys issue, problem persists

Kristian 2020-10-30T15:08:49.427800Z

Hey, I am trying to run a simple clojurescript program but I am getting hit with:

goog.addDependency("base.js", ['goog'], []);
^

ReferenceError: goog is not defined
When running node main.js after compiling my sources with lein cljsbuild once:
7   :cljsbuild {Ā¬
  6               :builds [{:id "main"Ā¬
  5                         :source-paths ["src"]Ā¬
  4                         :compiler {Ā¬
  3                                    :output-to "main.js"Ā¬
  2                                    :output-dir "out"Ā¬
  1                                    :optimizations :noneĀ¬
20                                     :source-map true}}]}Ā¬
Does anyone see the obvious mistake I am making?

Calum Boal 2020-10-30T15:09:02.427900Z

It was re-rendering properly before i added the subscription to peers-table

Kristian 2020-10-30T15:12:44.428100Z

FWIW: I am trying to use leiningen for dep management instead of the deps.edn that the Getting Started suggests

hipster coder 2020-10-30T15:20:11.428400Z

I remember running into problems with dependencies

hipster coder 2020-10-30T15:20:27.428600Z

because node versions changed how commonJS works, to incude outside modules

hipster coder 2020-10-30T15:20:43.428800Z

so first, you might want to look at your node version, and commonJS version

Kristian 2020-10-30T15:21:50.429Z

I just upgraded to latest node LTS. Is commonJS a part of node?

hipster coder 2020-10-30T15:22:49.429200Z

itā€™s a dependency module library, node sucked at including outside js, in the early days

hipster coder 2020-10-30T15:23:20.429500Z

can you verify that you have commonJS in your package.json?

Kristian 2020-10-30T15:23:27.429700Z

hm fair, fwiw it works to use deps.edn and the getting started launching with clj

Kristian 2020-10-30T15:24:08.429900Z

I donā€™t even have a package.json šŸ˜…

hipster coder 2020-10-30T15:25:26.430100Z

really? this is a node project? you are compiling to CLJS?

Kristian 2020-10-30T15:25:54.430300Z

my understanding was that cljsbuild would compile my .cljs to a .js which I could then serve directly with node. I might be completely off though

hipster coder 2020-10-30T15:26:17.430500Z

cljs, will convert to js, yes

hipster coder 2020-10-30T15:26:36.430700Z

but I really think you need your commonJS, package.json, 90% sure

hipster coder 2020-10-30T15:26:49.430900Z

or you canā€™t include dependencies

hipster coder 2020-10-30T15:26:58.431100Z

itā€™s an educated guess

hipster coder 2020-10-30T15:27:44.431300Z

hmm, but wait

hipster coder 2020-10-30T15:28:03.431500Z

it really looks like ā€˜googā€™ isnā€™t made available inside the base.js module

hipster coder 2020-10-30T15:28:22.431700Z

one sec

hipster coder 2020-10-30T15:29:40.431900Z

https://github.com/raml-org/datatype-expansion/issues/72

Calum Boal 2020-10-30T15:30:14.432200Z

Fixed it. This was the solution

(rf/reg-event-db
 :swap-asset
 (fn [db [_ asset]]
   (update-in db [:assets]
          (fn [assets asset]
            (conj
             (filter #(not= (:_id asset) (:_id %)) assets)
             asset))
          asset)))
Before it was:
(rf/reg-event-db
 :swap-asset
 (fn [db [_ asset]]
   (update-in db [:assets]
          (fn [db asset]
            (conj
             (filter #(not= (:_id asset) (:_id %)) (:assets db))
             asset))
          asset)))

Calum Boal 2020-10-30T15:30:39.432400Z

Thank you for helping me narrow down the issue, so many moving parts and i wasn't sure which bit i could have been fucking up

hipster coder 2020-10-30T15:31:09.432600Z

goog is the google-clojure libraryā€¦ it looks like

hipster coder 2020-10-30T15:31:11.432800Z

npm install google-closure-library

hipster coder 2020-10-30T15:31:23.433Z

I think you are missing itā€¦ and base.js wants it installed

Kristian 2020-10-30T15:31:50.433300Z

I did npm install goog earlier as well

hipster coder 2020-10-30T15:32:05.433700Z

ok, then you should have a package.json file

hipster coder 2020-10-30T15:32:27.433900Z

I would def stick to how node setups the project. with package.json

Kristian 2020-10-30T15:32:44.434100Z

I just got the package-lock.json, but I now created a node project as well

Kristian 2020-10-30T15:33:02.434300Z

the weird thing is that I know have a frankenstein of a leiningen and node project in the same folder

hipster coder 2020-10-30T15:33:20.434500Z

yepā€¦ I can screen shareā€¦ if you want

Kristian 2020-10-30T15:33:48.434700Z

ah no need. But thanks:) I will poke a bit more.

hipster coder 2020-10-30T15:33:58.434900Z

things are bit more calm on Fridays

Markus Str 2020-10-30T17:58:23.436700Z

Anybody know the canonical way to test browser events in cljs? I couldn't find a way to have a fixture of an js event that I can use as a variable (to test destructuring of a #js event for example)

unbalanced 2020-10-30T22:17:03.439400Z

if it's calling goog it's not compiling to node, it's compiling to the browser

unbalanced 2020-10-30T22:18:33.439600Z

https://figwheel.org/docs/nodejs.html

fabrao 2020-10-30T22:31:31.440200Z

hello all, I donĀ“t know if it is a strange question, but IĀ“m planning to make some compoments to PCF (Powerapps Component Framework) using Clojurescript and it works with, until now, with typescript. Is there any typescript mode output to use with Clojurescript?

p-himik 2020-10-31T08:46:39.440800Z

I don't know for sure but I really doubt that. TS can consume JS and CLJS produces JS - there should be no problems.