Content scripts do get updated for me without reload, with shadow cljs.
The only problem is when you navigate to another page, chrome loads the initial content script the extension started with.
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.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?
@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
Thanks for this figwheel resource too š Will report back on progress
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
.
Previous versions generated var d; for (d in a)
which was fine
maybe :language-out
will help...
right! :language-out :es5
solves the problem
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?
(rf/reg-sub
:active-server
:<- [:active-server-id]
:<- [:servers]
(fn [active-server-id servers _]
(first (filter #(= active-server-id (:_id %1)) servers))))
Ah figured it out. For reference it needs to be this:
(rf/reg-sub
:active-server
:<- [:active-server-id]
:<- [:servers]
(fn [[active-server-id servers] _]
(first (filter #(= active-server-id (:_id %1)) servers))))
If i call a component within another componenet, will it still be treated as a component and rerender when dereffed values change?
Because right now my nested components which deref things aren't being rerendered when the values in app-db change
(defn server-page []
[:section.section>div.container>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"]]
])
]]
))
Basically when there's a change, available-clients-table and peers-table doesn't re-render until i refresh the page
use [...]
instead of (...)
when working with components.
https://github.com/reagent-project/reagent/blob/master/doc/UsingSquareBracketsInsteadOfParens.md
Okay, done that, not solved the issue though š
Can post my subs if thhat helps
Sure.
Done, thanks for your help
You mean, you fixed the issue?
Ah, I see. Should've posted them in the thread.
I can't see anything obviously wrong. At this point, unless someone else sees something, I need a proper minimal reproducible example.
Nah not fixed the issue, and i thought the thread window might be too small. I can move them
Better move them, yeah. The thread can be expanded to the full width.
(rf/reg-sub
:assets
(fn [db _]
(:assets db)))
(rf/reg-sub
:active-server-id
(fn [db _]
(:active-server-id db)))
(rf/reg-sub
:servers
:<- [:assets]
(fn [assets _]
(filter asset/server? assets)))
(rf/reg-sub
:clients
:<- [:assets]
(fn [assets _]
(filter asset/client? assets)))
(rf/reg-sub
:active-server
:<- [:active-server-id]
:<- [:servers]
(fn [[active-server-id servers] _]
(first (filter #(= active-server-id (:_id %1)) servers))))
(rf/reg-sub
:available-clients
:<- [:clients]
(fn [clients _]
(filter #(=(count (:peers %1)) 0) clients)))
(rf/reg-sub
:server-peers
:<- [:clients]
(fn [clients [_ server]]
(filter #(asset/has-peer? server %1) clients)))
If i linked all the code would that help? If that's too much work to look through then no worries
Just create a small GitHub repo that I can clone and then run with a single command.
Okay will try add some data seeding
Here you go
You'll need mongo db but it'll seed itself
docker run --name=WirerunnerMongo -v /var/lib/WirerunnerMongo:/data/db -p 27017:27017 -d mongo
then just lein run and lein figwheel
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
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.
You can get rid of that argument if you like, it's just for container persistence
Which you wont need, just pasted the docker cmd i used to start it
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.
Figwheel: Starting server at <http://0.0.0.0:3449>
Did you do lein run, if so, it's 127.0.0.1:3000
OK, that seems to work.
Nice one, thank you for taking the time to help
There's a bunch of JS errors. Potentially, then can be the ones that cause your issues. Have you tried fixing them?
Only ones i was getting was Warning: Each child in a list should have a unique "key" prop.
You mean that?
And <th> cannot appear as a child of <thead>
.
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 confusingFixed that in one place but missed the other, done that now, not affecting it, will look at the warning
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?
I remember reading about Clojure being able to do something like that
I am using the actor model, for distributed computing
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
Docs say the warning just pertains to performance of updates
mhh interesting. I thought it would be something like a reference
Not sure what docs you're looking at, but that's not correct.
Ah, wait - I'm probably mixing it up with index keys.
Fixed the keys issue, problem persists
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?It was re-rendering properly before i added the subscription to peers-table
FWIW: I am trying to use leiningen for dep management instead of the deps.edn that the Getting Started suggests
I remember running into problems with dependencies
because node versions changed how commonJS works, to incude outside modules
so first, you might want to look at your node version, and commonJS version
I just upgraded to latest node LTS. Is commonJS a part of node?
itās a dependency module library, node sucked at including outside js, in the early days
can you verify that you have commonJS in your package.json?
hm fair, fwiw it works to use deps.edn and the getting started launching with clj
I donāt even have a package.json š
really? this is a node project? you are compiling to CLJS?
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
cljs, will convert to js, yes
but I really think you need your commonJS, package.json, 90% sure
or you canāt include dependencies
itās an educated guess
hmm, but wait
it really looks like āgoogā isnāt made available inside the base.js module
one sec
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)))
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
goog is the google-clojure libraryā¦ it looks like
npm install google-closure-library
I think you are missing itā¦ and base.js wants it installed
I did npm install goog earlier as well
ok, then you should have a package.json file
I would def stick to how node setups the project. with package.json
I just got the package-lock.json, but I now created a node project as well
the weird thing is that I know have a frankenstein of a leiningen and node project in the same folder
yepā¦ I can screen shareā¦ if you want
ah no need. But thanks:) I will poke a bit more.
things are bit more calm on Fridays
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)
if it's calling goog it's not compiling to node, it's compiling to the browser
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?
I don't know for sure but I really doubt that. TS can consume JS and CLJS produces JS - there should be no problems.