Index: trunk/parsers/wikidom/tests/synth/test.js |
— | — | @@ -167,16 +167,25 @@ |
168 | 168 | modelItem2 = new es.ModelContainerItem(), |
169 | 169 | modelItem3 = new es.ModelContainerItem(); |
170 | 170 | var viewContainer = new es.ViewContainer( modelContainer ); |
171 | | - viewContainer.createItemView = function( itemModel ) { |
172 | | - return new es.ViewContainerItem( itemModel ); |
173 | | - }; |
174 | | - |
| 171 | + |
175 | 172 | // |
176 | 173 | modelContainer.append( modelItem1 ); |
177 | 174 | 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]); |
179 | 184 | |
180 | | - equals( viewContainer.views.length, 3, 'es.ViewContainer' ); |
| 185 | + modelContainer.insertBefore( modelItem3, modelItem1 ); |
| 186 | + |
| 187 | + deepEqual(viewContainer.views, [viewContainerItem3, viewContainerItem1, viewContainerItem2]); |
| 188 | + |
| 189 | + |
181 | 190 | } ); |
182 | 191 | |
183 | 192 | function ContentStub( name, size ) { |
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js |
— | — | @@ -31,30 +31,36 @@ |
32 | 32 | var itemView = container.lookupItemView( itemModel ); |
33 | 33 | if ( itemView ) { |
34 | 34 | container.views.splice( container.views.indexOf( itemView ), 1 ); |
35 | | - itemView.$.remove(); |
| 35 | + itemView.$.detach(); |
36 | 36 | } |
37 | 37 | return itemView; |
38 | 38 | } |
39 | 39 | 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 | + } |
42 | 44 | container.views.unshift( itemView ); |
43 | 45 | container.$.prepend( itemView.$ ); |
44 | 46 | container.emit( 'prepend', itemView ); |
45 | 47 | container.emit( 'update' ); |
46 | 48 | } ); |
47 | 49 | 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 | + } |
50 | 54 | container.views.push( itemView ); |
51 | 55 | container.$.append( itemView.$ ); |
52 | 56 | container.emit( 'append', itemView ); |
53 | 57 | container.emit( 'update' ); |
54 | 58 | } ); |
55 | 59 | 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 | + } |
59 | 65 | if ( beforeView ) { |
60 | 66 | container.views.splice( container.views.indexOf( beforeView ), 0, itemView ); |
61 | 67 | itemView.$.insertBefore( beforeView.$ ); |
— | — | @@ -66,9 +72,11 @@ |
67 | 73 | container.emit( 'update' ); |
68 | 74 | } ); |
69 | 75 | 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 | + } |
73 | 81 | if ( afterView ) { |
74 | 82 | container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView ); |
75 | 83 | itemView.$.insertAfter( afterView.$ ); |