Fork me on GitHub

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
  {:fx/type :label
   :text (json/write-str message)})

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

(defn add-json-message
  (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?


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))


Thanks, I understand my error now 🙂


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


oh no, yet another chat app…