diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 97adec86..71c1c678 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -210,6 +210,28 @@ value) (list (quote set!) (hs-to-sx target) value))))))) (true (list (quote set!) (hs-to-sx target) value))))))) + ;; Throttle/debounce extraction state — module-level so they don't get + ;; redefined on every emit-on call (which was causing JIT churn). Set + ;; via _strip-throttle-debounce at the start of each emit-on, used in + ;; the handler-build step inside scan-on. + (define _throttle-ms nil) + (define _debounce-ms nil) + (define + _strip-throttle-debounce + (fn + (lst) + (cond + ((<= (len lst) 1) lst) + ((= (first lst) :throttle) + (do + (set! _throttle-ms (nth lst 1)) + (_strip-throttle-debounce (rest (rest lst))))) + ((= (first lst) :debounce) + (do + (set! _debounce-ms (nth lst 1)) + (_strip-throttle-debounce (rest (rest lst))))) + (true + (cons (first lst) (_strip-throttle-debounce (rest lst))))))) (define emit-on (fn @@ -218,27 +240,8 @@ ((parts (rest ast))) (let ((event-name (first parts))) - ;; Pre-extract :throttle and :debounce kwargs (handler-wrapping modifiers) - ;; from parts so scan-on doesn't need extra params. Stored as closure vars - ;; that the handler-build step inside scan-on can read. - (define _throttle-ms nil) - (define _debounce-ms nil) - (define - _strip-throttle-debounce - (fn - (lst) - (cond - ((<= (len lst) 1) lst) - ((= (first lst) :throttle) - (do - (set! _throttle-ms (nth lst 1)) - (_strip-throttle-debounce (rest (rest lst))))) - ((= (first lst) :debounce) - (do - (set! _debounce-ms (nth lst 1)) - (_strip-throttle-debounce (rest (rest lst))))) - (true - (cons (first lst) (_strip-throttle-debounce (rest lst))))))) + (set! _throttle-ms nil) + (set! _debounce-ms nil) (define scan-on (fn