Fork me on GitHub

How do I use debounce in combination with input on-change? I tried using goog.functions.debounce and goog.async Debouncer but I'm constantly running into "This synthetic event is reused for performance reasons....If you must keep the original synthetic event around, use event.persist()". Then I try adding (.persist e) but it doesn't help. I must be missing something but I've been stuck on this for hours. Any help is appreciated! Edit: Think I got it finally, this combination worked in case anyone is struggling with the same issue:

(:import [goog.async Debouncer])
(defn debounce [f interval]
  (let [dbnc (Debouncer. f interval)]
    (fn [& args] (.apply (.-fire dbnc) dbnc (to-array args)))))
(defn input-on-change [e]
  (.log js/console (.. e -target -value)))
(def input-on-change-debounced
  (debounce input-on-change 1000))
:on-change (fn [e]
               (.persist e)
               (input-on-change-debounced e))

Ronny Li00:11:39

Hi, I have a re-frame interceptor set up after every event to check the modified db against my spec (following using prismatic/schema). However, the schema validator fails when my db is first being initialized since it's simply an empty map at that point. As a result I get errors like schema problem: {:logged-in-user {:uid missing-required-key}} because the user hasn't logged in yet. I know I could set optional keys but that seems a bit counter-productive to me. Does anyone have a better solution?


Do you check your schema in an :after or a :before interceptor? You should use :after and have the very first event in your app set up the correct initial DB state.


BTW there's also #re-frame


Hi ! Is there a way of of defining a macro that will change the current namespace in clojurescript at the repl?

(defmacro def-in-core []
     (in-ns (quote cljs.core))
     (def a 42)))
This currently expands to (cljs.core/in-ns 'cljs.core) which doesn't exist. What I'm trying to acomplish is a macro that can create a def in a different ns.


No idea if it can work at all, but you can try adding ~' in front of in-ns.


this doesn't work in CLJS. in-ns is a special form that won't be handled when emitted like that


yeah I imagined, hmmm


@U05224H0W When using that macro (assuming in-ns is quoted) as

(def x 1)
(def y 2)
how is that not equivalent to
(def x 1)
  (in-ns 'cljs.core)
  (def a 42))
(def y 2)
? After all, macros expansion is done before CLJS compilation.


even the do will prevent in-ns from working


repl specials happen before macro expansion and not after


in CLJ these are all just functions so they all just work fine


in CLJS they are not


> repl specials happen before macro expansion and not after Oh. Huh. So in-ns doesn't exist outside of REPL at all in CLJS?

Use of undeclared Var clj-playground.core/in-ns


Thanks! Do you know of any comprehensive resource that would describe all the steps/stages and what specials available at which step/stage?


dont know about default CLJS anymore. the shadow-cljs specials are here


basically when in the REPL the specials take a different path through the compiler


everything else compiles normally


this is mostly because things like require may require async IO for loading files and stuff


thats why you can't have dynamic require in code also


I see. Thanks! > dont know about default CLJS anymore That evokes sad chuckles.


its definitely there and pretty sure it looks the same. just don't know where it is anymore 😉


Maybe I can use (goog/define "cljs.core.odd_QMARK_" (fn [n] 5)) or something like that if I want to lets say replace odd? in cljs.core :thinking_face:


I'm looking at the goog-define src


@U0739PUFQ no. you can use (set! cljs.core/odd? (fn [n] 5)) but not goog-define. be very careful doing this though.


oh that is better


I'm creating a instrument macro, and want to be able to do (trace-var cljs.core/map) so it grabs the source using source-fn, instrument it, and then replace the original with the instrumented version


it is working fine in clojure, but was having trouble in cljs


yeah this will be extremely difficult in CLJS


I'd suggest looking at the spec instrument function to see how it works


it can be done but it has all sorts of footguns


oh yeah I was going to take a look at instrument but forgot

Braden Shepherdson20:11:20

so apparently ClojureScript depends on a few parts of the API (eg. AnonymousFunctionNamingPolicy) that have been removed recently. in 20200920 for that enum specifically, not sure otherwise. is there a nightly or prerelease version of CLJS out there that works with the latest Closure compiler?


you could try asking in #cljs-dev