This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-30
Channels
- # aleph (4)
- # announcements (5)
- # architecture (1)
- # aws (5)
- # babashka (12)
- # beginners (143)
- # chlorine-clover (4)
- # cider (16)
- # clj-kondo (44)
- # cljfx (26)
- # cljsrn (2)
- # clojure (34)
- # clojure-europe (28)
- # clojure-gamedev (1)
- # clojure-nl (3)
- # clojure-provo (2)
- # clojure-spec (6)
- # clojure-uk (17)
- # clojurescript (99)
- # code-reviews (6)
- # core-async (15)
- # cryogen (9)
- # cursive (14)
- # data-science (1)
- # datomic (16)
- # duct (1)
- # events (4)
- # exercism (1)
- # figwheel-main (3)
- # fulcro (3)
- # hugsql (7)
- # leiningen (4)
- # malli (15)
- # off-topic (13)
- # pathom (8)
- # re-frame (7)
- # reitit (35)
- # remote-jobs (1)
- # sci (10)
- # shadow-cljs (32)
- # sql (5)
- # tools-deps (102)
- # tree-sitter (3)
- # uncomplicate (7)
- # vim (40)
- # xtdb (8)
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 ""))
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?
@UEJ5FMR6K 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
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
.
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"]]
])
]]
))
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
Done, thanks for your help
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
(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
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.
Did you do lein run, if so, it's 127.0.0.1:3000
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?
Fixed that in one place but missed the other, done that now, not affecting it, will look at the warning
Docs say the warning just pertains to performance of updates
Fixed the keys issue, problem persists
It was re-rendering properly before i added the subscription to peers-table
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
Basically when there's a change, available-clients-table and peers-table doesn't re-render until i refresh the page
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 confusingquick 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
mhh interesting. I thought it would be something like a reference
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?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
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?
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
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
ok, then you should have a package.json file
I would def stick to how node setups the project. with package.json
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
things are bit more calm on Fridays
if it's calling goog it's not compiling to node, it's compiling to the browser
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)