r96572 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96571‎ | r96572 | r96573 >
Date:14:59, 8 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Moved some repetitive code into the cleanup method, renamed it recycleItemView
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
@@ -27,29 +27,26 @@
2828 .addClass( 'editSurface-' + typeName )
2929 .data( typeName, this );
3030 var container = this;
31 - function cleanupItemView( itemModel ) {
 31+ function recycleItemView( itemModel, autoCreate ) {
3232 var itemView = container.lookupItemView( itemModel );
3333 if ( itemView ) {
3434 container.views.splice( container.views.indexOf( itemView ), 1 );
3535 itemView.$.detach();
3636 }
 37+ if ( autoCreate && itemView === null ) {
 38+ itemView = itemModel.createView();
 39+ }
3740 return itemView;
3841 }
3942 this.containerModel.on( 'prepend', function( itemModel ) {
40 - var itemView = cleanupItemView( itemModel );
41 - if ( itemView === null ) {
42 - itemView = itemModel.createView();
43 - }
 43+ var itemView = recycleItemView( itemModel, true );
4444 container.views.unshift( itemView );
4545 container.$.prepend( itemView.$ );
4646 container.emit( 'prepend', itemView );
4747 container.emit( 'update' );
4848 } );
4949 this.containerModel.on( 'append', function( itemModel ) {
50 - var itemView = cleanupItemView( itemModel );
51 - if ( itemView === null ) {
52 - itemView = itemModel.createView();
53 - }
 50+ var itemView = recycleItemView( itemModel, true );
5451 container.views.push( itemView );
5552 container.$.append( itemView.$ );
5653 container.emit( 'append', itemView );
@@ -57,10 +54,7 @@
5855 } );
5956 this.containerModel.on( 'insertBefore', function( itemModel, beforeModel ) {
6057 var beforeView = container.lookupItemView( beforeModel ),
61 - itemView = cleanupItemView( itemModel );
62 - if ( itemView === null ) {
63 - itemView = itemModel.createView();
64 - }
 58+ itemView = recycleItemView( itemModel, true );
6559 if ( beforeView ) {
6660 container.views.splice( container.views.indexOf( beforeView ), 0, itemView );
6761 itemView.$.insertBefore( beforeView.$ );
@@ -73,10 +67,7 @@
7468 } );
7569 this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) {
7670 var afterView = container.lookupItemView( afterModel ),
77 - itemView = cleanupItemView( itemModel );
78 - if ( itemView === null ) {
79 - itemView = itemModel.createView();
80 - }
 71+ itemView = recycleItemView( itemModel, true );
8172 if ( afterView ) {
8273 container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView );
8374 itemView.$.insertAfter( afterView.$ );
@@ -88,7 +79,7 @@
8980 container.emit( 'update' );
9081 } );
9182 this.containerModel.on( 'remove', function( itemModel ) {
92 - var itemView = cleanupItemView( itemModel );
 83+ var itemView = recycleItemView( itemModel );
9384 container.emit( 'remove', itemView );
9485 container.emit( 'update' );
9586 } );

Status & tagging log