r96514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96513‎ | r96514 | r96515 >
Date:22:45, 7 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Finished moving view creation to model items.
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.BlockView.js (modified) (history)
  • /trunk/parsers/wikidom/tests/synth/test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/synth/test.js
@@ -32,6 +32,10 @@
3333 container1.append( item3 );
3434 equal( updates, 3, 'es.ModelContainer emits update events on append' );
3535 strictEqual( item3.c, container1, 'es.ModelContainer.append attaches item to container' );
 36+
 37+ strictEqual( item1.a, container1, 'Item container is set upon adding' );
 38+ strictEqual( item2.b, container1, 'Item container is set upon adding' );
 39+ strictEqual( item3.c, container1, 'Item container is set upon adding' );
3640
3741 // Accessing
3842
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
@@ -28,22 +28,22 @@
2929 .data( typeName, this );
3030 var container = this;
3131 this.containerModel.on( 'prepend', function( itemModel ) {
32 - var itemView = container.createItemView( itemModel );
 32+ var itemView = itemModel.createView();
3333 container.views.unshift( itemView );
3434 container.$.prepend( itemView.$ );
3535 container.emit( 'prepend', itemView );
3636 container.emit( 'update' );
3737 } );
3838 this.containerModel.on( 'append', function( itemModel ) {
39 - var itemView = container.createItemView( itemModel );
 39+ var itemView = itemModel.createView();
4040 container.views.push( itemView );
4141 container.$.append( itemView.$ );
4242 container.emit( 'append', itemView );
4343 container.emit( 'update' );
4444 } );
45 - this.containerModel.on( 'insertBefore', function( item, before ) {
46 - var itemView = container.createItemView( item ),
47 - beforeView = container.lookupItemView( before );
 45+ this.containerModel.on( 'insertBefore', function( itemModel, beforeModel ) {
 46+ var itemView = itemModel.createView(),
 47+ beforeView = container.lookupItemView( beforebeforeModel );
4848 if ( beforeView ) {
4949 container.views.splice( container.views.indexOf( beforeView ), 0, itemView );
5050 itemView.$.insertBefore( beforeView.$ );
@@ -55,7 +55,7 @@
5656 container.emit( 'update' );
5757 } );
5858 this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) {
59 - var itemView = container.createItemView( item ),
 59+ var itemView = itemModel.createView(),
6060 afterView = container.lookupItemView( afterModel );
6161 if ( afterView ) {
6262 container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView );
@@ -77,7 +77,7 @@
7878 // Auto-add views for existing items
7979 var itemModels = this.containerModel.all();
8080 for ( var i = 0; i < itemModels.length; i++ ) {
81 - this.views.push( this.createItemView( itemModels[i] ) );
 81+ this.views.push( itemModels[i].createView() );
8282 }
8383 };
8484
@@ -90,10 +90,6 @@
9191 return null;
9292 };
9393
94 -es.ViewContainer.prototype.createItemView = function( itemModel ) {
95 - throw 'es.ViewContainer.createItemView not implemented in this subclass';
96 -};
97 -
9894 /* Inheritance */
9995
10096 es.extend( es.ViewContainer, es.EventEmitter );
Index: trunk/parsers/wikidom/lib/synth/views/es.BlockView.js
@@ -9,7 +9,7 @@
1010 * @param tagName {String} HTML tag name to use in rendering (optional, default: "div")
1111 */
1212 es.BlockView = function( typeName, tagName ) {
13 - es.DomContainerItem.call( this, 'document', typeName || 'block', tagName || 'div' );
 13+ es.ViewContainerItem.call( this, 'document', typeName || 'block', tagName || 'div' );
1414 };
1515
1616 /**
@@ -40,4 +40,4 @@
4141 throw 'BlockView.getRenderedLineIndex not implemented in this subclass.';
4242 };
4343
44 -es.extend( es.BlockView, es.DomContainerItem );
 44+es.extend( es.BlockView, es.ViewContainerItem );

Status & tagging log