|
|
|
|
|
by lobster_johnson
4439 days ago
|
|
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. |
|