ebpa / tui.el

An experimental text-based UI framework for Emacs modeled after React - **requires emacs 26.1 or newer**

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request for Assistance with tui.el Component Not Redrawing Despite State Change.

opened this issue · comments

Hi ebpa,

Thank you for creating the tui.el library. I have a question about its usage:

I expect to force update the component with a timer, then reassign the time-string value, and have the interface automatically redrawn, but it did not automatically re-render. Here is an example code:

(tui-defun-2 time-test (&state (time-string (current-time-string))
                           (timer (tui-run-with-timer
                                   component 1 1 t
                                   (lambda ()
                                     (tui-force-update component)))))
  "A basic timer test"
  (tui-span
   (format "\ntime: %s" time-string)))

(setq time-test-comp (time-test))
(tui-render-element time-test-comp)

I have tried to solve this issue on my own, but have been unsuccessful so far. Can you please provide some guidance or suggest a solution?

Thank you for your time and help.

Here's what I get when I macroexpand the definition (using M-x emacs-lisp-macroexpand)

(tui-define-component time-test :documentation "A basic timer test" :get-initial-state
  (lambda
    (this)
    (tui--with-prop-state-bindings
      (this nil nil)
      (-let*
          ((time-string
            (current-time-string))
           (timer
            (tui-run-with-timer component 1 1 t
                                (lambda nil
                                  (tui-force-update component)))))
        (list :time-string time-string :timer timer))))
  :render
  (lambda
    (this)
    (tui--with-prop-state-bindings
      (this nil
            (time-string timer))
      (tui-span
       (format "\ntime: %s" time-string)))))

This component is rendering every second but it never updates the state.

Rather than force-updating the component, just update the state:

(tui-defun-2 time-test (&state (time-string (current-time-string))
                           (timer (tui-run-with-timer
                                   component 1 1 t
                                   (lambda ()
                                     (tui-set-state
                                      component
                                      (list :time-string (current-time-string)))))))
  "A basic timer test"
  (tui-span
   (format "\ntime: %s" time-string)))