@smith.adriane thanks for the reply. As I said its just an experiment for now, and I can see advantages (and disadvantages) to all the approaches you mention. Is there some mechanism in membrane to assist with: > put all state in a db, all effects update the db and the ui queries the db (with caching) when it needs to re-render. Where would I “hook into” the re-render process to trigger db queries?
I just uploaded a proof of concept I made previously that integrates with datascript, https://github.com/phronmophobic/membrane-datascript
it's a little messy since it's a just a proof of concept
basically, every graphics backend has a run
function.
example usage:
https://github.com/phronmophobic/membrane-datascript/blob/main/src/com/phronemophobic/membrane_datascript.clj#L141 )
every backend's run
function accepts a 0 arity function that should return a view when called. (for a more in-depth explanation see https://blog.phronemophobic.com/ui-model.html)
this is the UI's view-function as mentioned in the design blog posts
the view function will be called whenever it's time to rerender
really, the short answer is that membrane doesn't have a framework that packages everything
One of the problems membrane tries to address is that UI code tends to absorb the rest of your application. You end up with react-http, react-db, react-async, etc. Membrane tries to build user interfaces out of simpler pieces so that you don't need membrane specific libraries for non ui related code. If you need caching, you just use a caching library. If you need http, just use any http library.
not sure if any of that makes sense
Meaning the view
function you provide should somehow incorporate the necessary queries, caching, etc. I guess that makes sense!
Am I right when this means I should not rely on the component/make-app function that membrane provides? Because that function has its own take on state management
Great, then I’m slowly getting there 🙂
in the datascript example, you can see it has it's own version of make-app
, https://github.com/phronmophobic/membrane-datascript/blob/main/src/com/phronemophobic/membrane_datascript.clj#L104
you're doing great. I realize there's a pretty steep learning curve. Thanks for giving it a try 😄
and make-app's responsibility is to build and return the 0 arity view function, https://github.com/phronmophobic/membrane-datascript/blob/main/src/com/phronemophobic/membrane_datascript.clj#L117
It's pretty late here, so I'm going to have to head out. Hopefully, the example helps!
I’m sure it will, but will look at it later tonight. Thanks for all the help!
@smith.adriane sending this now so it will be there when you’re day starts again (I think we are in very different timezones). 🙂
Does the event-loop in run
also execute the view function when no events have been received? I’m asking because I’m trying to understand how the ui can respond to changes to the closed over state that do not originate from events but from the “outside”.
It depends on the backend. Some of them will check if the view returns something different at least every second regardless. Usually there’s a way to ask for a repaint.