This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-15
Channels
- # adventofcode (13)
- # aleph (5)
- # announcements (8)
- # beginners (87)
- # calva (9)
- # cider (102)
- # cljs-dev (71)
- # cljsrn (2)
- # clojure (198)
- # clojure-dev (28)
- # clojure-europe (3)
- # clojure-italy (27)
- # clojure-nl (3)
- # clojure-spec (1)
- # clojure-uk (43)
- # clojurescript (121)
- # component (11)
- # cursive (20)
- # data-science (13)
- # datascript (2)
- # datomic (102)
- # dirac (4)
- # duct (5)
- # emacs (14)
- # figwheel-main (7)
- # fulcro (37)
- # hoplon (11)
- # jackdaw (3)
- # jobs (2)
- # leiningen (16)
- # nrepl (2)
- # off-topic (51)
- # pathom (34)
- # pedestal (12)
- # perun (10)
- # portkey (1)
- # re-frame (6)
- # reitit (1)
- # shadow-cljs (21)
- # spacemacs (8)
- # tools-deps (2)
- # vim (2)
I found this old thread on the google group discussing binding
in CLJS
https://groups.google.com/forum/#!topic/clojure/6cmnkHmHBNw
The main point is this
user=> (def ^:dynamic x "root")
#'user/x
user=> x
"root"
user=> #'x
#'user/x
user=> ((binding [x "dynamic"] (fn [] x)))
"root"
Is there a work around to make binded vars respect local bindings when used within nested functions?
i think the nature of dynamic vars is that their value is set by the current binding. your fn is constructed in the binding but is evaluated after the binding
if you move the binding out of the invocation it should work, or if you capture the current binding into a non dynamic var
@currentoor your example is equivalent to this form:
(let [f (binding [x "dynamic"]
(fn [] x))]
(f))
where it should be clear that the binding is no longer in effect@dpsutton thanks, this this seems to work
(def ^:dynamic x "root")
(defn foo []
x)
(binding [x "dynamic"]
(foo))
but for some reason when i do this across an iframe element in react it doesn’t get the dynamic valuue
perhaps i’m doing something wrong
i’ll play with my code more
i have a modal library i’m using, and i want to bind a *mount-node*
var to an iframe’s document.body
whenever a component is used inside an iframe
and default to the outermost document.body
whenever the component is used in a regular context
is there any reason that shouldn’t work?
@lilactown great idea!, thanks
Hi, I have the following code to create a Firebase Cloud Function that reacts when an entry is added to the database:
(ns gcf.core
(:require ["firebase-functions" :as fb-fn]))
(defn db-ref []
(.ref (.-database fb-fn) "/trollbox/{messageId}"))
(def translate-fn
(.onCreate (db-ref)
(fn [snapshot context]
(println "Executing function...")
(println (str "Value: " (.val snapshot))))))
(def exports #js {:translateHTTP translate-fn})
It's working fine when I test locally using the firebase shell, but when I deploy to firebase I get the following error when the function is invoked:
TypeError: a.D is not a function
at /user_code/gcf.js:247:1067
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:779:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Looks like the code for (.val snapshot)
is the one causing the issue because the function works when I remove it.
Any ideas on how I can debug this?
I'm using shadow-cljs with the following configuration:
shadow-cljs.edn
{:source-paths ["src"]
:builds {:gcf {:target :node-library
:main gcf.core/main
:output-to "gcf.js"
:exports-var gcf.core/exports}}}
packages.json
{
"name": "functions",
"description": "CLJS Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^7.0.0",
"firebase-functions": "^2.1.0"
},
"private": true
}
you can try building with shadow-cljs release --debug
and see if that gives any more info
it sounds like (.val snapshot)
is being optimized into something. changing it to (.val ^js snapshot)
might fix it
@artrmrno add :compiler-options {:infer-externs :auto}
to your build config and you'll get a warning that you need to typehint the .val
invoke. Also :main
does not apply to :node-library
configs, you can remove that.
Hi guys!I have a seemingly big issue with figwheel. I cannot for the life of it get the figwheel repl to work not even thinking about getting it to work with cider. I have now tried it for days and with all the famous linux distros (arch, debian, ubuntu, fedora,...). I just wanted to get a simple project to work to get it eventually to work with cider, because that introduces another set of possible issues and I haven't got it to work. So I cloned the example flappy-bird-demo-new project and ran
lein fig:build
. After that the website with the game opens and I see the repl prompt in my terminal (cljs.user ==>). I can do that several times and it works. BUT: as soon as I reboot and try again to build it with
lein fig:build
I only see the message Opening url http//:localhost:9500
After that it just stays there and nothing happens.I also completely deleted the project, cloned it again and ran
lein fig:build
...Nothing. I also tried it with the clj tools version. Same thing. Also any other project and create from a leiningen figwheel template does not give me a cljs prompt.I'm getting really frustrated, because I cannot figure out what the problem is. I also did not find anything online about it.
So your browser doesn't open with the localhost url? What happens if you open it manually? Btw there's a dedicated #figwheel-main channel
The CLJS prompt opens once the browser successfully connects to figwheel. It should report to the console.
log:Opening the WebSocket on logger.js:367:5
[goog.net.WebSocket] Opening the WebSocket on console.js:203:20
log:WebSocket opened on logger.js:367:5
[goog.net.WebSocket] WebSocket opened on console.js:203:20
log:Session ID: e69315e5-95e0-4101-90c7-9908d271cec0 logger.js:367:5
[Figwheel REPL] Session ID: e69315e5-95e0-4101-90c7-9908d271cec0 console.js:203:20
log:Session Name: Rosie logger.js:367:5
[Figwheel REPL] Session Name: Rosie
The thing I don't get is. Why does it happen after a reboot? I created some snapshots on my virtual machine before and after I built the project the first time and after the restart. If I go back to the snapshot where I have not yet built the project it always works. As soon as I reboot I don't get the prompt anymore.
Seems like the browser is connecting fine. Sounds weird, I'm not sure what could be the problem.
Can anyone offer a pointer on how to create a command line vanilla (non-lein, figwheel) REPL for a Clojurescript project that can access installed node_modules?
All in the same directory I have a src
folder, a deps.edn
that includes src
in :paths
, package.json
and node_modules
with installed modules.
I can boot a REPL with clj -m cljs.main -re node
, and it can find my code. But it can't find the installed Node modules.
ClojureScript 1.10.439
cljs.user=> (require '[db.etl.staging])
module.js:545
throw err;
^
Error: Cannot find module 'aws-sdk'
at Function.Module._resolveFilename (module.
...
Any pointers?I'm suprised that nobody else seems to have the same problem. As I said, I tried it with several different Linux distros and with jdk 11. On my Virtualbox and directly on my laptop. I always have the same issue.
yes. and for testing puposes I have another asus laptop on which I run Windows 10 and Virtualbox.
ok. let's stay in linux on the thinkpad. it's lein 2.9.0, figwheel-main 0.2.0, correct?
Ok. Leining is 2.9.0, Java is 1.8.0_202 and the figwheel-main version from the sample project is 0.1.5
FWIW I had to bump figwheel main yesterday to 0.2.0 when I tried to use it with Clojure 1.10. Dunno if that helps
OK. So I changed it in the project.clj of the flappy-bird-demo-new project but I still have the same problem
can you paste the alias in your project.clj that fig:build is supposed to be invoking?
thing is. even if i try to create to most simple project with only a folder and a deps.edn with the following line:
{:deps {com.bhauman/figwheel-main {:mvn/version "0.2.0"}}}
Even then I don't get to the prompt.ok. so i cloned that project, ran lein fig:build and immediately it opened up my browser and i started playing flappybird
i didn't bump figwheel main or anything. so there's something up with your install it seems
The problem is, that the last thing I see in my terminal after I started the project is:
Opening URL
i'm still not quite following. when you open it manually, it behaves the same as when it works automatically. and in neither case do you get a connected repl?
i got the game visible. is your screen just plain white? does it say something like "keep on figwheelin'"
if I run the project on a freshly installed system then after the last line I get a prompt like:
cljs.user==>
ok. this is what you get when the browser seems to be working? it never connects back? And again there are no vms involved, no docker, no shenanigans?
ok. sorry i was so dense. just wanted to make sure i understood exactly what was going on
look in the sources tab in the browser console. we can check if figwheel main is putting its required things to start figwheel