r96530 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96529‎ | r96530 | r96531 >
Date:00:42, 8 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Fix few problems and bugs in ViewContainer + tests
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js (modified) (history)
  • /trunk/parsers/wikidom/tests/synth/test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/synth/test.js
@@ -167,16 +167,25 @@
168168 modelItem2 = new es.ModelContainerItem(),
169169 modelItem3 = new es.ModelContainerItem();
170170 var viewContainer = new es.ViewContainer( modelContainer );
171 - viewContainer.createItemView = function( itemModel ) {
172 - return new es.ViewContainerItem( itemModel );
173 - };
174 -
 171+
175172 //
176173 modelContainer.append( modelItem1 );
177174 modelContainer.append( modelItem2 );
178 - modelContainer.append( modelItem2 );
 175+ modelContainer.append( modelItem3 );
 176+
 177+ equals( viewContainer.views.length, 3, 'es.ViewContainer' );
 178+
 179+ var viewContainerItem1 = viewContainer.views[0],
 180+ viewContainerItem2 = viewContainer.views[1],
 181+ viewContainerItem3 = viewContainer.views[2];
 182+
 183+ deepEqual(viewContainer.views, [viewContainerItem1, viewContainerItem2, viewContainerItem3]);
179184
180 - equals( viewContainer.views.length, 3, 'es.ViewContainer' );
 185+ modelContainer.insertBefore( modelItem3, modelItem1 );
 186+
 187+ deepEqual(viewContainer.views, [viewContainerItem3, viewContainerItem1, viewContainerItem2]);
 188+
 189+
181190 } );
182191
183192 function ContentStub( name, size ) {
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
@@ -31,30 +31,36 @@
3232 var itemView = container.lookupItemView( itemModel );
3333 if ( itemView ) {
3434 container.views.splice( container.views.indexOf( itemView ), 1 );
35 - itemView.$.remove();
 35+ itemView.$.detach();
3636 }
3737 return itemView;
3838 }
3939 this.containerModel.on( 'prepend', function( itemModel ) {
40 - cleanupItemView( itemModel );
41 - var itemView = itemModel.createView();
 40+ var itemView = cleanupItemView( itemModel );
 41+ if ( itemView === null ) {
 42+ itemView = itemModel.createView();
 43+ }
4244 container.views.unshift( itemView );
4345 container.$.prepend( itemView.$ );
4446 container.emit( 'prepend', itemView );
4547 container.emit( 'update' );
4648 } );
4749 this.containerModel.on( 'append', function( itemModel ) {
48 - cleanupItemView( itemModel );
49 - var itemView = itemModel.createView();
 50+ var itemView = cleanupItemView( itemModel );
 51+ if ( itemView === null ) {
 52+ itemView = itemModel.createView();
 53+ }
5054 container.views.push( itemView );
5155 container.$.append( itemView.$ );
5256 container.emit( 'append', itemView );
5357 container.emit( 'update' );
5458 } );
5559 this.containerModel.on( 'insertBefore', function( itemModel, beforeModel ) {
56 - cleanupItemView( itemModel );
57 - var itemView = itemModel.createView(),
58 - beforeView = container.lookupItemView( beforeModel );
 60+ var beforeView = container.lookupItemView( beforeModel ),
 61+ itemView = cleanupItemView( itemModel );
 62+ if ( itemView === null ) {
 63+ itemView = itemModel.createView();
 64+ }
5965 if ( beforeView ) {
6066 container.views.splice( container.views.indexOf( beforeView ), 0, itemView );
6167 itemView.$.insertBefore( beforeView.$ );
@@ -66,9 +72,11 @@
6773 container.emit( 'update' );
6874 } );
6975 this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) {
70 - cleanupItemView( itemModel );
71 - var itemView = itemModel.createView(),
72 - afterView = container.lookupItemView( afterModel );
 76+ var afterView = container.lookupItemView( afterModel ),
 77+ itemView = cleanupItemView( itemModel );
 78+ if ( itemView === null ) {
 79+ itemView = itemModel.createView();
 80+ }
7381 if ( afterView ) {
7482 container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView );
7583 itemView.$.insertAfter( afterView.$ );

Status & tagging log