Bitburger-New View API Notes


Use Cases

The new view API is designed around the following use cases:

 

  1. The program needs to display a dialog with a number of controls.  We need to get the final HTML for the dialog generated and on the screen as fast as possible.  This generally means trying to create this HTML, including having all the values filled in and event handlers setup, with as little real DOM manipulation as possible.
  2. A CollectionView needs to display a list of 100,000 contacts.  We must support incremental rendering - i.e. rendering only the HTML that is on the screen.  When the user scrolls slowly, we should add/remove just the HTML needed to fill the newly visible area.  When the user jerks the scrollbar quickly down, we must be able to quickly redraw the entire visible area. 
  3. A CollectionView needs to display a list comments static layout.  In this case, we need to display a stacked list of comments which may have different unknown heights.  We need to be able to simply render the HTML for these comments and allow the browser to do the layout.  The comments should still support having buttons and other controls internally.  It is OK to sacrifice incremental rendering in this case.
  4. A TableView needs to display 10 columns.  A table view is a lot like a list view with multiple columns.  We need to be able to rapidly render all 10 columns without have to create (n x m) views for the display.  Reusable views would be very useful here.

 

Current Status

The basic code for SC.View has been hacked in.  SC.LabelView has also been updated to use the new render API.  SC.RenderContext has been created and it pretty well unit tested.  We still need to:

 

  1. Add unit testing for all methods on SC.View
  2. Update SC.Pane to use the new approach -- specifically to lazily create the layer DOM for its child views when it goes on screen.
  3. Update SC.ContainerView, SC.SplitView, and SC.ButtonView just to get some sense of whether this new API will work as we expect or not. 
  4. If it does, then we need to convert the rest of the views over.

 

The code for the new API is currently on the new-view-api branch in the staging repository.

 

Current Design Notes

These notes just document the current concepts in source.  They may change at any time.

 

Layers

 

 

Creating a Layer

 

Updating a Layer

 

FrameSupport & Layout

 

 

SC.RenderContext

 

 

Testing Requirements

 

 

Example Code

Here is how you would write a basic HelloWorld view:

 

MyApp.HelloWorldView = SC.View.extend({

  value: "Hello World",

 

  displayProperties: 'value',  // automatically update layer if value changes

  render: function(context, firstName) {

    context.text(this.get('value')); // text will escape HTML

  }

});

 

Here is how you might blend SC.View with YUI (derived from YUI examples):

 

MyApp.AutocompleteView = SC.View.extend({

   // a YUI 'DataSource' object 

   dataSource: null,

 

  // add required initial content 

  render: function(context) {

     context.push("<input id='myInput' /><div id='myContainer' ></div>");

  },

  // setup YUI JS when layer is created

  didCreateLayer: function() {

    this.yui = new YAHOO.widget.AutoComplete("myInput", "myContainer",

       this.get('dataSource')); 

  }

});