phronmophobic/membrane

Improve repl support when updating supporting functions in repl

phronmophobic opened this issue · 0 comments

Due to the way component caching works, re-evaling helper functions that are used by defui components, but aren't defui components will make it seem like something is broken.

(defn helper-fn []
  (ui/label "hi"))
(defui my-component [{}]
  (helper-fn))

(ui/children (my-component {}))
;; [{:text "hi",
;;   :font {:name nil, :size 14, :weight nil, :width nil, :slant nil}}]

;; re-eval
(defn helper-fn []
  (ui/label "hello"))
;; uses cache
(ui/children (my-component {}))
;; [#membrane.ui.Label{:text "hi", :font #membrane.ui.Font{:name nil, :size 14, :weight nil, :width nil, :slant nil}}]

;; re-eval
(defui my-component [{}]
  (helper-fn))
(ui/children (my-component {}))
;; [#membrane.ui.Label{:text "hello", :font #membrane.ui.Font{:name nil, :size 14, :weight nil, :width nil, :slant nil}}]

There are various ways to invalidate the cache so that this is more convenient when working at the repl.

  • debug mode that flushes cache regularly
  • better documentation
  • nrepl middleware
  • add a skia/debug-run that helps?