cljfx

https://github.com/cljfx/cljfx
sundbp 2019-03-29T11:46:53.024900Z

What is the idiomatic way to just close down cljfx components? Say in a reloaded typ work flow on (reset) (I'm using integrant). If I have used create-app and have the return of that, how to i cleanly "close" it down?

vlaaad 2019-03-29T12:07:43.026100Z

create-app returns a map with renderer on :renderer key. You should call renderer function with nil

sundbp 2019-03-29T12:09:35.027200Z

Ok. So that will "clear" the scene so to say. Anything one should do in terms of disposing renderer itself?

vlaaad 2019-03-29T12:10:47.028200Z

there is nothing to dispose in renderer itself, but I just remembered that you might also want to unmount renderer from *context atom

vlaaad 2019-03-29T12:12:36.029600Z

there is no function to unmount in public api yet, I'll make an issue to add it, until then you can just call (remove-watch *context ['cljfx.renderer/mount renderer])

vlaaad 2019-03-29T12:16:10.030400Z

@sundbp created https://github.com/cljfx/cljfx/issues/9

sundbp 2019-03-29T12:24:48.032200Z

Cool!

vlaaad 2019-03-29T12:25:02.032700Z

Not sure if it's worth it, but if you want to be extra sure about ordering and stuff, you might want to deref returned value from (renderer nil), it'll block until next javafx frame that will dispose ui.

sundbp 2019-03-29T12:25:05.032900Z

Thanks. I'm liking the project a lot so far.

vlaaad 2019-03-29T12:25:17.033200Z

:bananadance:

sundbp 2019-03-29T14:25:46.033800Z

Worked well btw.

👍 1
sundbp 2019-03-29T17:27:37.035500Z

Question: I have a need for a timer to trigger updates to context to be reflected in rendered UI. What is the correct pattern to follow for this?

vlaaad 2019-03-29T17:33:15.035600Z

There is AnimationTimer in JavaFX, I would just create a proxy of it and put it in a context so I can stop it when needed. There is no special way to describe timers in cljfx declaratively, because I haven't figured out how to describe them declaratively.

sundbp 2019-03-29T17:47:25.036Z

Ok. Will try that. Thanks

sundbp 2019-03-29T17:49:43.037500Z

So my animation timer captures the context in lexical scope, then uses fx/swap-context to update state?

vlaaad 2019-03-29T18:15:13.037900Z

Not sure I understand your question

sundbp 2019-03-29T18:18:51.038800Z

I'll study a bit and come back.

vlaaad 2019-03-29T18:46:11.038900Z

Just thought that if you are going to do fx/swap-context in a timer and display and render some kind of timer ui (like elapsed time updated in real-time), you really should use core.cache with a cache that will not grow forever, because otherwise it will leak memory with all previous ui descriptions cached by elapsed time that will never be reused since it is just increasing

sundbp 2019-03-29T19:24:06.041400Z

It isn't high frequency. I was referring to timer more broadly as async thing triggered outside of the javafx event system. I reckon all I actually need is to have a ref to the context and use fx/swap-context.