▲ | MrJohz 3 days ago | ||||||||||||||||
How do you update the html when something changes? For me, that's the most interesting question for these sorts of micro-frameworks - templating HTML or DOM nodes is super easy, but managing state and updates is hard. | |||||||||||||||||
▲ | dleeftink 3 days ago | parent | next [-] | ||||||||||||||||
I find the coroutine/generator approach described in a series of posts by Lorenzo Fox/Laurent Renard to be a promising alternative[0]. It takes a little to wrap your head around, but essentially structures component rendering to follow the natural lifecycle of a generator function that takes as input the state of a previous yield, and can be automatically cleaned up by calling `finally` (you can observe to co-routine state update part in this notebook[1]). This approach amounts to a really terse co-routine microframework [2]. [0]: https://lorenzofox.dev/posts/component-as-infinite-loop/#:~:... | |||||||||||||||||
▲ | lylejantzi3rd 3 days ago | parent | prev [-] | ||||||||||||||||
I call printPosts with the new post data. It rewrites the whole chunk in one go, which is pretty snappy. I haven't decided how I'm going to handle more granular updates yet, like comment count or likes. | |||||||||||||||||
|