HS: when :count changes — scoped watch + parse-cmd feature boundary fix
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
Three-part fix for element-scoped reactive expressions: 1. Parser: add when/bind to parse-cmd's feature-keyword nil set so `... then when X changes ...` is parsed as a new feature, not absorbed into the preceding on-handler body as a (ref "when") expression. 2. Parser: parse-when-feat now recognises local (:var) token type so `when :count changes ...` dispatches to the when-changes branch. 3. Runtime + compiler: hs-scoped-set! now fires hs-scoped-fire-watchers! on change; new hs-scoped-watch! / hs-scoped-fire-watchers! registry; compiler emits (hs-scoped-watch! me name (fn (it) body)) for local expressions in when-changes AST nodes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1686,7 +1686,34 @@
|
||||
|
||||
(define
|
||||
hs-scoped-set!
|
||||
(fn (el name val) (dom-set-data el (str "hs-local-" name) val)))
|
||||
(fn
|
||||
(el name val)
|
||||
(let
|
||||
((changed (not (= (hs-scoped-get el name) val))))
|
||||
(do
|
||||
(dom-set-data el (str "hs-local-" name) val)
|
||||
(when changed (hs-scoped-fire-watchers! el name val))))))
|
||||
|
||||
(begin
|
||||
(define _hs-scoped-watchers (list))
|
||||
(define
|
||||
hs-scoped-watch!
|
||||
(fn
|
||||
(el name handler)
|
||||
(set!
|
||||
_hs-scoped-watchers
|
||||
(cons (list el name handler) _hs-scoped-watchers))))
|
||||
(define
|
||||
hs-scoped-fire-watchers!
|
||||
(fn
|
||||
(el name val)
|
||||
(for-each
|
||||
(fn
|
||||
(entry)
|
||||
(when
|
||||
(and (= (nth entry 0) el) (= (nth entry 1) name))
|
||||
((nth entry 2) val)))
|
||||
_hs-scoped-watchers))))
|
||||
|
||||
(define
|
||||
hs-scoped-get
|
||||
@@ -2701,6 +2728,8 @@
|
||||
(if match (dom-parent match) nil)))
|
||||
(true el))))))
|
||||
|
||||
;; ── SourceInfo API ────────────────────────────────────────────────
|
||||
|
||||
(define
|
||||
hs-dom-walk
|
||||
(fn
|
||||
@@ -2711,8 +2740,6 @@
|
||||
((= (dom-get-attr el "dom-scope") "isolated") nil)
|
||||
(true (hs-dom-walk (dom-parent el) name)))))
|
||||
|
||||
;; ── SourceInfo API ────────────────────────────────────────────────
|
||||
|
||||
(define
|
||||
hs-dom-find-owner
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user