Fork me on GitHub
#membrane
<
2022-03-01
>
Richie04:03:29

Can you offer advice on how to develop... iteratively? incrementally? live? whatever people call it... I want my code changes to get incorporated into the running app.

Richie04:03:31

(defonce app (atom nil))

(defn view
  [& args]
  (ui/label "hi"))

(reset! app (java2d/run (component/make-app #'view)))
I have this ^ Even if I change something in view and call ((:membrane.java2d/repaint @app)) nothing changes in the ui.

phronmophobic05:03:28

@UPD88PGNT, You can try something like:

(defonce app (atom nil))

(defn view
  [& args]
  (ui/label "hi"))

(def window-info (java2d/run #'view))
(def repaint (::java2d/repaint window-info))

(add-watch #'view ::repaint
           (fn [_ _ _ _]
             (repaint)))

phronmophobic05:03:51

The issue is that component/make-app only works with components created with component/defui.

phronmophobic05:03:06

If you're not using defui and friends, then you can just pass the function.

Richie12:03:20

Woa, neat. I forgot add-watch worked for more than just atoms.

Richie15:03:38

Why can't I edit text in my textarea?

Richie15:03:22

(defui view
  [arg]
  (basic/textarea {:text "hi"}))

(defonce window (java2d/run
                  (component/make-app #'view {})))

((:membrane.java2d/repaint window))
I can highlight the text but I can't edit it. I think I should be able to since the tutorial example shows editing the text in the gif.

Richie15:03:35

It works if I copy over the example. I can figure this out.

Richie15:03:06

Oh.

(defui view
  [{:keys [input]
    :or {input ""}}]
  (basic/textarea {:text input}))
I have to rerun the app if I change the name input. I guess the app is populating :input in the context and if I redef the defui to use like :my-input then there's no data there.

Richie15:03:51

No data there in the context.

phronmophobic18:03:21

It looks like you figured it out, but since textareas are stateful components, the :text property must be derived from some input property to "update" it.