Hacker News new | ask | show | jobs
by johnzabroski 4437 days ago
Let me rephrase my objection once more.

In graphics programming, it is customary to have a Scene Graph which is a Model that represents the scene you need to Render.

In Desktop/Web programming for business apps, this design pattern/abstraction step seems completely absent, and developers seem to continuously mush together view and model.

What "composition" can't be achieved simply by having a Knockout Virtual Element, or Template Selector driven by a ViewModel property?

2 comments

Well, in your graphics programming example, the "scene graph" consists of UI objects. It doesn't consider of logical objects such as players, enemies and explosions; it consists of frames, meshes, textures, etc., all of which are part of the "view". The logical model (players, etc.) is used to populate the scene graph. The scene graph itself is used as the basis of the composition pipeline that uses something like OpenGL.

React, as well as this library, are pretty much exactly like this, except you replace OpenGL with the DOM. They are purely about managing UI state; they provide the controller (C) and view (V) parts of MVC, and leave the model (M) aspect to the developer to work out using some other library. For example, it's entirely feasible to combine React with Backbone models. Unlike traditional MVC, however, the responsibilities of the controller are generally handled by the view itself.

The composition that they are talking about is about treating components as first-class objects. For example, in React, you can do this (via JSX, a preprocessor for JavaScript that allows you to embed HTML in JS):

    Toolbar = React.createClass({
      render: function() {
        return <div className='toolbar'>
          <Button onClick={this.handleSave} icon="save" label="Save document"/>
          <Button onClick={this.handleClose} icon="close" label="Close document"/>
        </div>;
      }
    });
Here, Button is not a real HTML element, but another component which is embedded in the parent component. By expressing this as a pseudo-element, it's possible to treat it as a black box that knows how to render itself.
> developers seem to continuously mush together view and model.

It used to be, but it less likely with recent frameworks. I don't know Knockout. I read a little about it seems like some kind of HMVC but more like mMVC where m = mess.

Reactive can be used with KJS. KJS has observables, and the RP library will be plug to that.

Reactive Programming is about reacting to events, like bindings Model to View: if another user +fav this post, an updated will be pushed to all others and the new score will appear. You can also bind other behaviors to non-data "models" like xhr pool.