Address code review feedback: improve comments and test cleanup

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-20 14:52:05 +00:00
parent d176d2e7cb
commit 6d34267f1c
2 changed files with 11 additions and 8 deletions

View File

@ -2845,8 +2845,11 @@ incorrectly generate an anonymous tp-name instead of using the layer name."
(ert-deftest tp-test-redefine-layer-updates-watchers ()
"Test that re-defining a layer updates :watch correctly."
(tp-test-with-temp-buffer
;; Use defvar to create dynamically-bound variables that watcher callbacks can access
(defvar tp-test-watch-log-old nil "Log for old watcher.")
(defvar tp-test-watch-log-new nil "Log for new watcher.")
(setq tp-test-watch-log-old nil)
(setq tp-test-watch-log-new nil)
(unwind-protect
(progn
;; First definition with old watcher
@ -2968,8 +2971,8 @@ incorrectly generate an anonymous tp-name instead of using the layer name."
:props (face (:background $tp-test-applied-color))
:data ((tp-test-applied-color . "blue")))
;; The text should now have the new color
;; Note: This happens because re-definition updates the variable,
;; which triggers the reactive update mechanism
;; This happens because tp-define-layer calls tp--update-layer-regions
;; at the end to update all text regions with the new properties
(should (equal (plist-get (get-text-property 1 'face) :background) "blue")))
;; Cleanup
(ignore-errors (makunbound 'tp-test-applied-color)))))

12
tp.el
View File

@ -2072,7 +2072,7 @@ The layer is stored in `tp-layer-alist'."
(if (or all-reactive-syms data compute)
;; Has reactive features - register dependencies and resolve at runtime
`(progn
;; Clean up old dependencies first (for re-definition)
;; Clean up old reactive dependencies, watchers, computed properties, and data (for re-definition)
(tp--unregister-reactive-deps ',name)
;; Ensure all reactive variables are defined
(tp--ensure-reactive-variables ',all-vars-to-define)
@ -2098,7 +2098,7 @@ The layer is stored in `tp-layer-alist'."
(assoc ',name tp-layer-alist))
;; No reactive symbols - use static properties
`(progn
;; Clean up old dependencies first (for re-definition from reactive to non-reactive)
;; Clean up old reactive dependencies, watchers, computed properties, and data (for re-definition)
(tp--unregister-reactive-deps ',name)
(tp--set-layer-props ',name ',properties)
;; Update any text regions that already have this layer applied
@ -2265,7 +2265,7 @@ and the group itself is stored in `tp-layer-groups'."
(if (or all-reactive-syms data compute)
;; Has reactive features - register dependencies and resolve at runtime
(push `(progn
;; Clean up old dependencies first (for re-definition)
;; Clean up old reactive dependencies, watchers, computed properties, and data (for re-definition)
(tp--unregister-reactive-deps ',layer-name)
;; Ensure all reactive variables are defined
(tp--ensure-reactive-variables ',all-vars-to-define)
@ -2290,7 +2290,7 @@ and the group itself is stored in `tp-layer-groups'."
layer-defs)
;; No reactive symbols - use static properties
(push `(progn
;; Clean up old dependencies first (for re-definition)
;; Clean up old reactive dependencies, watchers, computed properties, and data (for re-definition)
(tp--unregister-reactive-deps ',layer-name)
(tp--set-layer-props ',layer-name ',props)
;; Update any text regions that already have this layer applied
@ -2305,7 +2305,7 @@ and the group itself is stored in `tp-layer-groups'."
(if reactive-syms
;; Has reactive symbols - register dependencies and resolve at runtime
(push `(progn
;; Clean up old dependencies first (for re-definition)
;; Clean up old reactive dependencies, watchers, computed properties, and data (for re-definition)
(tp--unregister-reactive-deps ',layer-name)
(tp--ensure-reactive-variables
',(mapcar #'tp--reactive-var-symbol reactive-syms))
@ -2318,7 +2318,7 @@ and the group itself is stored in `tp-layer-groups'."
layer-defs)
;; No reactive symbols - use static properties
(push `(progn
;; Clean up old dependencies first (for re-definition)
;; Clean up old reactive dependencies, watchers, computed properties, and data (for re-definition)
(tp--unregister-reactive-deps ',layer-name)
(tp--set-layer-props ',layer-name ',props)
;; Update any text regions that already have this layer applied