membrane

Richie 2022-03-01T04:09:29.033819Z

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.

Richie 2022-03-01T04:10:31.499859Z

(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.

Richie 2022-03-01T04:11:13.127459Z

Thanks!

phronmophobic 2022-03-01T05:08:28.928509Z

@rgkirch, 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)))

phronmophobic 2022-03-01T05:08:51.240129Z

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

phronmophobic 2022-03-01T05:10:06.796719Z

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

Richie 2022-03-01T12:47:20.426779Z

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

Richie 2022-03-01T15:07:38.400029Z

Why can't I edit text in my textarea?

Richie 2022-03-01T15:08:22.522409Z

(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.

Richie 2022-03-01T15:12:35.409709Z

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

Richie 2022-03-01T15:22:06.684999Z

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.

Richie 2022-03-01T15:22:51.264359Z

No data there in the context.

phronmophobic 2022-03-01T18:18:21.778039Z

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.