This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-16
Channels
- # beginners (81)
- # calva (6)
- # cider (21)
- # clj-kondo (2)
- # clojure (62)
- # clojure-austin (3)
- # clojure-europe (3)
- # clojure-italy (20)
- # clojure-nl (39)
- # clojure-russia (4)
- # clojure-spec (19)
- # clojure-uk (23)
- # clojurescript (76)
- # cursive (6)
- # data-science (9)
- # datomic (12)
- # defnpodcast (1)
- # figwheel-main (3)
- # fulcro (8)
- # jackdaw (5)
- # jobs (1)
- # jobs-discuss (18)
- # joker (1)
- # leiningen (2)
- # liberator (2)
- # off-topic (148)
- # onyx (5)
- # pedestal (39)
- # planck (7)
- # re-frame (5)
- # reagent (3)
- # reitit (37)
- # shadow-cljs (165)
- # tools-deps (1)
- # yada (19)
greetings! what can/should I do to import {_esModule: true}
with shadow-cljs
?
strange thing is: it worked few minutes ago, but after some reloads and extra deps - it broke, and all I can see is in chrome console is:
(ns slate
(:require ["slate" :as slate]))
(js/console.log slate)
;; {_esModule: true} with an Object prototype methods.
cleaning target and recompile anew did not help.omfg this was the reason: https://github.com/thheller/shadow-cljs/pull/480/commits/2f56f7499ec9e1a16ea6d63c4c19ce8485e1de81
not sure though how it worked w/o utf-8
in the first place (created a project from this "template" https://github.com/minimal-xyz/minimal-shadow-cljs-browser linked to from the http://shadow-cljs.org/ home page)
@misha FWIW __esModule
is just a marker property created by babel to indicate that the source was an ES module converted to CommonJS
I know, but imports were working (even with Uncaught SyntaxError: Invalid regular expression
error from PR), but then broke, and broke in random way every time I cleaned up and rebuilt
(I know I know, you cannot rely on anything in JS after 1st error in console, but it did work for tens of minutes at first)
and since template project's index.html is just <div><script></script></div>
- it screwed me over
can someone tell me how to get “user stops typing” thingy? why this doesn’t work as expected:
(defn- on-key-up [ev]
(.persist ev)
(go
(<! (timeout 1000))
(js/console.log "sending request for:" (.-target .-value ev))))
If I type “help”, it waits for a second but shows “sending request” 4 times.
I want to wait for user to stop typing and then send a single requestyou are running a separate timeout
for each on-key-up
event
You could use alts!
to wait for a new key or the timeout. alts!
returns the matched channel. if timeout -> send reques
can someone show me a snippet that works… using goog.async.Debouncer - I’m still seeing multiple messages in the console
(defn debounce [f interval]
(let [dbnc (Debouncer. f interval)]
;; We use apply here to support functions of various arities
(fn [& args] (.apply (.-fire dbnc) dbnc (to-array args)))))
(defn- on-key-up [ev]
(.persist ev)
(let [dfn (debounce #(js/console.log "sending request for:" (utils/target-val ev)) 1000)]
(dfn)))
(ns my-app
(:require [goog.functions :as gfn]))
(def send-req!
(gfn/debounce
(fn [ev] (js/console.log "sending request for:" (-> ev .-target .-value))
1000))
(defn- on-key-up [ev]
(.persist ev)
(send-req! ev))
this is so trivial to get it right with rxjs or similar, it makes me mad I can’t get it work
I guess I’m gonna try plain-old setTimeout/clearTimeout but I’ll have to store the timeout somewhere. I guess I’ll store it in an atom…
(def last-timeout (atom nil))
(defn- on-key-up [ev]
(js/clearTimeout @last-timeout)
(.persist ev)
(reset!
last-timeout
(js/setTimeout
#(js/console.log "sending request: " (utils/target-val ev))
1000)))
the source for it is pretty much what you wrote: https://github.com/google/closure-library/blob/master/closure/goog/functions/functions.js#L420
look… these guys do the same thing https://github.com/MattiNieminen/re-fill/blob/bba5c1f5e92d5758961ca580247ae4dcd5844ae4/src/re_fill/debounce.cljs
(do (send-req! "foo") (send-req! "bar"))
only fires "foo"
. but (send-req! "foo") (send-req! "bar")
fires it for "foo"
and "bar"
@ag @lilactown send-req!
creates new anonymous fn on each call. def it first.
I had the same behavior before, when I gave goog.functions.debounce
new fn on each call.
@mfikes I've been trying to get self hosted Cljs to recognize 'ambient' functions in a precompiled library. Using the functions directly from Cljs (via figwheel and cljs-repl) works just fine. I've also read https://stackoverflow.com/questions/51573858/how-can-i-run-eval-in-clojurescript-with-access-to-the-namespace-that-is-calling/51575204#51575204 and https://stackoverflow.com/questions/50828008/how-can-i-make-functions-available-to-clojurescripts-eval. Those are somewhat enlightening but kind of opaque as well. In any event, when I try the technique outlined in the former, what I currently run into is env/compiler is nil instead of an atom with something in it. However, I am trying to call the cljs.js/load-analysis-cache!
directly, not via a macro. Any ideas/insights most appreciated.
@mfikes second question : If the 'ambient' library is compiled with advanced optimization, can it be used in a self hosted client. I know that the client can only be compiled with 'simple' optimization, but I am wondering about the library.
@jsa-aerial If you use cljs.js
then env/*compiler*
is bound for you. Are you experiencing a nil
value when using the ambient
project?
I'm just requiring cljs.js and cljs.env
@jsa-aerial It would be odd to have a mixture of :advanced
and :simple
running in the same JavaScript engine. But in theory if you managed to load an :advanced
version of the ambient
library in, you'd at least need to mark the my-inc
function with ^:export
For the nil
env/*compiler*
you'll probably have to provide a minimal repro to make any sense of that—in other words, would need to know the exact setup you're running through to cause that
Hmmmm, the library is one that is built and available as an artifact.
OK, I need to go now, but will try to put something together that shows what I am experiencing.
Maybe it has something to do with the order things are required?
Well, env/*compiler*
is a dynamic var that gets bound when you call certain functions in cljs.js
You have to call something in cljs.js
before env/*compiler*
is initialized?
what would that be?
Oh, I'm re-reading that SO. There are two env/*compiler*
instances at play.
So, just need to know exactly what you are doing.
OK, I think have this mostly figured out. I'm now guessing that the two env/*compiler*
instances are, one in the JVM and one in the JS (browser). Then some 'magic' happens where when evaluating cljs.js/load-analysis-cache!
in the browser communicates with the JVM side and retrieves its env/*compiler*
data and puts it the JS env/*compiler*
state.
@mfikes ^^^^ Also, interestingly enough, I can call the advanced optimized functions of the ambient lib(??)
I guess the last question I have now is - how would you go about achieving this in a build? Right now, I'm just evaluating the load-analysis-cache!
in the repl