improve code
This commit is contained in:
parent
3c698dea8a
commit
250a51ea22
24
tp.el
24
tp.el
@ -297,7 +297,8 @@ Returns an updated override-alist with the new computed values."
|
|||||||
do (setq all-reactive-props
|
do (setq all-reactive-props
|
||||||
(plist-put all-reactive-props key val))))))
|
(plist-put all-reactive-props key val))))))
|
||||||
(when all-reactive-props
|
(when all-reactive-props
|
||||||
(let ((resolved-props (tp--resolve-reactive-symbols all-reactive-props override-alist)))
|
(let ((resolved-props (tp--resolve-reactive-symbols
|
||||||
|
all-reactive-props override-alist)))
|
||||||
(when resolved-props
|
(when resolved-props
|
||||||
(cl-loop for (key val) on resolved-props by #'cddr
|
(cl-loop for (key val) on resolved-props by #'cddr
|
||||||
do (setq current-props (plist-put current-props key val)))
|
do (setq current-props (plist-put current-props key val)))
|
||||||
@ -372,7 +373,8 @@ Also adds variable watchers so changes to data vars trigger computed updates."
|
|||||||
(dolist (var-sym var-symbols)
|
(dolist (var-sym var-symbols)
|
||||||
(let ((existing (assoc var-sym tp-reactive-deps)))
|
(let ((existing (assoc var-sym tp-reactive-deps)))
|
||||||
(if existing
|
(if existing
|
||||||
;; Add this layer to existing dependencies (with nil props since data vars don't have direct props)
|
;; Add this layer to existing dependencies
|
||||||
|
;; (with nil props since data vars don't have direct props)
|
||||||
(let ((layer-entry (assoc layer-name (cdr existing))))
|
(let ((layer-entry (assoc layer-name (cdr existing))))
|
||||||
(unless layer-entry
|
(unless layer-entry
|
||||||
(push (cons layer-name nil) (cdr existing))))
|
(push (cons layer-name nil) (cdr existing))))
|
||||||
@ -392,7 +394,8 @@ If a variable is not bound, define it with the initial value (nil if not specifi
|
|||||||
(let* ((is-cons (and (consp sym) (not (tp--reactive-symbol-p sym))))
|
(let* ((is-cons (and (consp sym) (not (tp--reactive-symbol-p sym))))
|
||||||
(var-sym (cond
|
(var-sym (cond
|
||||||
(is-cons (car sym))
|
(is-cons (car sym))
|
||||||
((tp--reactive-symbol-p sym) (tp--reactive-var-symbol sym))
|
((tp--reactive-symbol-p sym)
|
||||||
|
(tp--reactive-var-symbol sym))
|
||||||
(t sym)))
|
(t sym)))
|
||||||
(initial-val (if is-cons (cdr sym) nil)))
|
(initial-val (if is-cons (cdr sym) nil)))
|
||||||
(unless (boundp var-sym)
|
(unless (boundp var-sym)
|
||||||
@ -409,13 +412,14 @@ Re-applies the layer properties using tp-search-map and tp-add."
|
|||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
;; Use tp-search-map to find all regions with this layer
|
;; Use tp-search-map to find all regions with this layer
|
||||||
;; The callback uses start and end to set properties directly
|
;; The callback uses start and end to set properties directly
|
||||||
(tp-search-map
|
(save-excursion
|
||||||
(lambda (_text start end)
|
(tp-search-map
|
||||||
;; Apply the new properties directly to the buffer region
|
(lambda (_text start end)
|
||||||
(tp-add start end props)
|
;; Apply the new properties directly to the buffer region
|
||||||
;; Return nil to skip text replacement
|
(tp-add start end props)
|
||||||
nil)
|
;; Return nil to skip text replacement
|
||||||
'tp-name layer-name)))))))
|
nil)
|
||||||
|
'tp-name layer-name))))))))
|
||||||
|
|
||||||
(defun tp-reactive-reset ()
|
(defun tp-reactive-reset ()
|
||||||
"Reset all reactive text property watchers and dependencies."
|
"Reset all reactive text property watchers and dependencies."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user