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?
create-app
returns a map with renderer
on :renderer
key. You should call renderer function with nil
Ok. So that will "clear" the scene so to say. Anything one should do in terms of disposing renderer itself?
there is nothing to dispose in renderer itself, but I just remembered that you might also want to unmount renderer from *context
atom
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])
see https://github.com/cljfx/cljfx/blob/master/src/cljfx/renderer.clj#L77
Cool!
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.
Thanks. I'm liking the project a lot so far.
:bananadance:
Worked well btw.
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?
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.
Ok. Will try that. Thanks
So my animation timer captures the context in lexical scope, then uses fx/swap-context to update state?
Not sure I understand your question
I'll study a bit and come back.
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
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.