News for hackers. Stuff that matters.
Re:Virtual DOM is pure overhead (2018) by WA on Sunday May 19, 2019 @06:08AM (#19952481)
If you’ve ever written a video game, I think it’s quite obvious as well. Video games have a main loop, take input, compute the next state, and then merely render the state to the screen. There is no point in manipulating the "UI". The data flow is very clear.

Of course, your game can run entirely "in memory" without a render function, which is basically what the game server does.

So I guess, many people have figured it out but didn’t transfer the knowledge from one area to the other.

Thanks for the insight, because I also always wondered what’s considered so new about React, although I have to admit that I still wrote my fair share of jQuery Spaghetti code.

Re:Virtual DOM is pure overhead (2018) by barrkel on Sunday May 19, 2019 @07:48AM (#19952833)
Before anybody runs away and thinks there's a fundamental insight here, I have to say that all that's really changing is who owns the retained model: application or UI library.

I mean retained by contrast with immediate, as in the early DirectX jargon.

By retained model, I mean the source of truth as to the current state of the UI. Games normally use an immediate mode API, but they still render the UI from a model; it's just that they own the model, whereas with UI toolkits, you generally manipulate a model the UI toolkit maintains and the UI toolkit renders from that model.

Retained mode UIs are much easier to start with. You can get something that looks good up and running very quickly, because you don't need to think through the best representation for your UI - skilled designers and engineers have already done the work, and developed composition and drawing routines so that it all hangs together.

The trouble starts in more sophisticated applications, where the internal model has grown more complex, and UI code is increasingly an exercise in duplicating changes from one model to the other, via reactive techniques like data binding, or more imperatively from events. Having components denormalize state is a recipe for desynchronization bugs.

The problem doesn't totally go away if you move wholesale to immediate mode where the app owns the model, though. There are UI concerns that don't really belong in most application models; things like focus, selection, non-local UI idioms like radio buttons, caret position in text, etc. Doing these things right involves a lot of subtle design. Most app developers are better off handing these concerns to experts who focus on them.

Re:Virtual DOM is pure overhead (2018) by weberc2 on Sunday May 19, 2019 @10:34AM (#19953455)
How are these other state concerns you mention (e.g., focus) handles in immediate mode GUIs? Do the components retain those states or do you keep a separate model for those states that needs to interact with the application model? If so, how is that interaction wired up?
Re:Virtual DOM is pure overhead (2018) by ppeetteerr on Sunday May 19, 2019 @05:29PM (#19955625)
I would argue that the state of the global model includes some information about the state of a widget (e.g. selected="true") and some state is unique to the widget itself (hover).

The trick here is how do you reconcile those two states when both have a copy of the data. For instance, the <input type="text" /> holds its own state and you hold the value in the global state. When a user types a character into the input, the input hold a copy of the letter in its "value", and the state is updated with the same value, which then triggers the input to compare its state with that of the global state for equality before attempting to render the value in the global state. Tricky stuff.

Re:Virtual DOM is pure overhead (2018) by weberc2 on Sunday May 19, 2019 @06:57PM (#19956101)
If I understand correctly, the distinction between immediate mode GUI and retained is that in the former, there aren’t stateful widgets so there is no copy to reconcile.
Re:Virtual DOM is pure overhead (2018) by beetwenty on Sunday May 19, 2019 @11:17PM (#19957283)
That's correct. State is handled by the user, which is great for some things(dynamic quantities of elements - no caching layers, just feed it a for loop) and awful for others(maintaining pre-committed state for e.g. a configuration panel with checkboxes, text fields, etc.)

Ultimately the ground truth in both instances is that you have potentially many data models that the UI has to aggregate, and the source model, layout, display properties and hitboxes of elements are usually but not totally related and can change due to many kinds of events. Any formal structure you might come up with is bound to run into exceptions. As a result I tend to have this policy:

* I don't trust the framework

* But I leverage the framework to produce early results, and both immediate and retained modes offer ways of doing that

* I expect long-term maintenance to involve a customized framework design regardless

Re:Virtual DOM is pure overhead (2018) by weberc2 on Sunday May 19, 2019 @02:08PM (#19954568)
S/handles/handled
Re:Virtual DOM is pure overhead (2018) by mpfundstein on Sunday May 19, 2019 @03:46PM (#19955071)
You can edit your posts after you have posted them
Re:Virtual DOM is pure overhead (2018) by weberc2 on Sunday May 19, 2019 @03:58PM (#19955144)
The edit window had already expired.
Re:Virtual DOM is pure overhead (2018) by Udik on Sunday May 19, 2019 @06:32AM (#19952580)
> Video games have a main loop, take input, compute the next state, and then merely render the state to the screen. There is no point in manipulating the "UI". The data flow is very clear.

I always thought this is basically the MVC pattern. And it's obviously the only sane way to do things.

Edit: I don't mind the donwvotes, but am I wrong? The MVC pattern simply seems to mandate, at its core, the separation between the model, its graphical representation, and the input from the user. Input -> model -> view. So a game loop where the user input is gathered, the model is updated by calculating the next state, and the view is displayed seems to me an instance of MVC.

Re:Virtual DOM is pure overhead (2018) by e12e on Sunday May 19, 2019 @09:23AM (#19953166)
Didn't down vote, but the original mvc was a bit subtler than that - originally dubbed user-model-view-controller - the idea was that the user has a mental model of the domain, and the computer has a concrete data model - and the user can act on a view via controllers to translate changes in their mental model to the underlying data model.

(one example of this, while not very graphical, might be a withdrawal from a bank account;the program stores a transaction - the user sees a "Change" in amount available in the account - in the user's mind there's 300 dollars in the account before withdrawing 100 dollars, and 200 after - but this view is a (beneficial lie - the "account" is merely a sum of transactions).

In short mvc wasn't really about a tight mapping between widgets and internal state of the data model - but about translating between the users idea of the domain model and the implementation.

But certainly implementing mvc in a object/message oriented language like smalltalk leads to data flow of input event > controller translation > model update > view update.

More at:

http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html

I recommend reading the paper, it's short and an easy read.

Re:Virtual DOM is pure overhead (2018) by coldtea on Sunday May 19, 2019 @07:48AM (#19952832)
Actually that's one way to do things, the two ways being retained mode and immediate mode.

And each has their own use cases and challenges.

Traditionally, however, most well known GUIs (most of the apps people use on the desktop) were done with retained mode libraries (GTK, Qt, Cocoa, and so on).

>So a game loop where the user input is gathered, the model is updated by calculating the next state, and the view is displayed seems to me an instance of MVC.

There's nothing preventing the view being a retained mode UI widget tree -- which is how MVC was commonly implemented iirc.

Re:Virtual DOM is pure overhead (2018) by vijaybritto on Sunday May 19, 2019 @08:09AM (#19952910)
Though your opinion is mostly right, I think people are downvoting for the sentence "obviously the only same way to do things"