Hey Baste! Thanks for taking the time to dig in
And for sure, you may not be the target audience for a framework like this. A few clarifications:
This is just a proof of concept. I put it together in a week, to see if I could put together a way to express UI that’s more palatable to folks coming from the React world (which even though it’s the most popular way to build modern web apps, is no stranger to controversy in that world). In that spirit, I’ve specifically avoided addressing obvious performance tasks, like freeing up objects, using a weak event manager, or anything but the most basic optimizations. I’m focusing more on expressiveness and correctness in reconciliation than I am on perf.
“by adding a pretty large framework”
I wouldn’t call it large - it’s around 11kb, including samples…
“The reason why it’s easier is that every time the UI needs to change due to an event, the entire View object is regenerated from scratch. Then, behind the scenes, that’s turned into VisualElements through a framework that tries to automatically pool those VisualElements by figuring out if it’s the same ones that are getting reused.”
Yew updates subtrees when those subtrees have changed. So we aren’t regenerating the entire hierarchy each time from scratch. And the thinking here, which matches Reacts, is that these are cheap objects to generate. If/when we get record types, Yew would like to use those. creating and disposing small, short-lived objects isn’t free, but it’s a lot better than bigger, longer running objects with lots of references.
“The way I’d do this from scratch in C# is to have event listeners in the correct spots that adds and removes just the parts of the UI that needs to be added or removed. That’s harder to get right, but it’s for sure doable.”
In my experience, this is what tends not to scale well as your app’s UI becomes more complex. The reason why React is popular with so many millions of developers is because doing all of that precise, manual targeting of updating becomes unmanageable when you are working on production class applications, and the web industry made the decision that it’s worth taking a modest hit in runtime performance to allow their teams to build richer, more maintainable, higher quality applications.
“Yew:
Add button is pressed
New todo entry is added to the todo list
Entire Yew representation is recreated from scratch
Yew walks the VisualElement hierarchy to figure out if there are updates needed
The new VisualElement is created as a side-effect of the above.”
This is sort of true, for this sample. However (as I point out in the yew documentation), the use of ‘method components’ is for lighter weight areas, and for prototyping. As UI complexity grows, those can be migrated easily to regular View/Components, which will then not need to render their child hierarchies, unless their state changes. So, say you had a list of 100 complex item components, you can provide lightweight views for them, and only when the view has changed, do you need to pay the cost to rebuild that subtree.
"Since it’s so slow, you can only really use it if you don’t care about the performance or are prototyping. "
Have you downloaded and ran the samples and benchmarked their performance? If so, thank you! and please share the numbers! Otherwise, please do before you lob baseless accusations.
"Also, the UseAtom stuff is the most overengineered Dictionary<string, object> I have seen in my life. "
Thanks for the additional kind words
I won’t defend the UseAtom code. That represented about 30 minutes of the week long project. I don’t know if I’d use them either. it’s more about just trying things out, to see if they stick at this point. FWIW, the atoms come from recoil (https://recoiljs.org/), and are considered experimental over in the web world too. I’m planning on playing with the idea a bit more, but yeah, I wouldn’t use them at this point in production.
“Finally, the way you load stylesheets by using the AssetDatabase API doesn’t work in builds. That’s an Editor only API, so you either have to load the stylesheet from resources, or link it when you combine the ui document and the Yew component.”
good to know. you have a link? I’ll get that sorted.
Thanks again Baste, even though it’s clearly not to your taste, I appreciate the time to understand it at the level you did.
And yes, I agree with the assessment that this is NOT production ready! It’s a week old project! At this point, I’m really just curious if there’s any interest in this approach of expressing UI. I know it’s a popular paradigm in the web world, but I really know nothing about UI opinions in Unity. All I know is that I found the state of UI in Unity rough enough that it was worth it to me, for my own sanity, to have a go at creating some of the familiar tools and concepts I love from the web world.