cljfx

https://github.com/cljfx/cljfx
AidanJH 2020-11-23T03:13:18.157900Z

Hello Folks! I am trying to build a UI that is updated with information that I receive from another service via file pipe. Ive gotten as far as creating a context that contains the updates from my external service and now I am trying to update the context with the messages as they come in. The project readme wasnt very clear on the use of fx/swap-context. Ive tried using it a few ways and have not been successful. Here is my context and update function (add-json-message):

.......

;; simple permutation of json into label
(defn paint-message
  [message]
  {:fx/type :label
   :text (json/write-str message)})

;; atomic global state for the UI
(def main-context  (atom (fx/create-context
                          {:contacts []
                           :messages []}
                         cache/lru-cache-factory)))

(defn add-json-message
  [obj]
  (fx/swap-context main-context conj :messages (paint-message obj)))

.........
And heres my error:
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.concurrent.Future.get()" because "fut" is null
Can someone help clarify how to properly use swap-context?

vlaaad 2020-11-23T08:06:45.158700Z

Hi! swap-context is a pure function (hence the absence of ! at the end), it creates a new context from old context. You have to combine it with swap! to mutate atom, e.g. (swap! main-context fx/swap-context update :messages conj (paint-message obj))

AidanJH 2020-11-23T18:18:22.159200Z

Thanks, I understand my error now 🙂

AidanJH 2020-11-23T03:19:38.158500Z

Also curious: does this project have a room on matrix by chance?

vlaaad 2020-11-23T08:08:24.159100Z

oh no, yet another chat app…