r96698 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96697‎ | r96698 | r96699 >
Date:21:53, 9 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Cleanup for event emitters and subscribers
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ContentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js
@@ -8,7 +8,11 @@
99 */
1010 es.ParagraphBlockModel = function( content ) {
1111 es.BlockModel.call( this, ['hasContent', 'isAnnotatable'] );
12 - this.content = content || null;
 12+ this.content = content || new es.ContentModel();
 13+ var model = this;
 14+ this.content.on( 'change', function() {
 15+ model.emit( 'update' );
 16+ } );
1317 };
1418
1519 /* Static Methods */
Index: trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js
@@ -9,7 +9,11 @@
1010 es.ListBlockModel = function( items ) {
1111 es.BlockModel.call( this, ['hasContent', 'isAnnotatable', 'isAggregate'] );
1212 es.ModelContainer.call( this );
13 - this.items = new es.AggregateArray( items || [] );
 13+ if ( $.isArray( items ) ) {
 14+ for ( var i = 0; i < items.length; i++ ) {
 15+ this.append( items[i] );
 16+ }
 17+ }
1418 };
1519
1620 /* Static Methods */
Index: trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
@@ -433,7 +433,7 @@
434434 'offset': offset,
435435 'content': content
436436 } );
437 - this.emit( 'change', { 'type': 'insert' } );
 437+ this.emit( 'update', { 'type': 'insert' } );
438438 };
439439
440440 /**
@@ -450,7 +450,7 @@
451451 this.emit( 'remove', {
452452 'range': range
453453 } );
454 - this.emit( 'change', { 'type': 'remove' } );
 454+ this.emit( 'update', { 'type': 'remove' } );
455455 };
456456
457457 /**
@@ -463,7 +463,7 @@
464464 es.ContentModel.prototype.clear = function() {
465465 this.data = [];
466466 this.emit( 'clear' );
467 - this.emit( 'change', { 'type': 'clear' } );
 467+ this.emit( 'update', { 'type': 'clear' } );
468468 };
469469
470470 /**
@@ -568,7 +568,7 @@
569569 'annotation': annotation,
570570 'range': range
571571 } );
572 - this.emit( 'change', { 'type': 'annotate' } );
 572+ this.emit( 'update', { 'type': 'annotate' } );
573573 };
574574
575575 es.extend( es.ContentModel, es.EventEmitter );
Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js
@@ -114,16 +114,12 @@
115115 var parent = item.parent();
116116 if ( parent === this ) {
117117 this[this._listName].splice( this.indexOf( item ), 1 );
118 - this[this._listName].push( item );
119 - } else {
120 - if ( parent ) {
121 - parent.remove( item );
122 - }
123 - this[this._listName].push( item );
124 - var container = this;
125 - item.on( 'update', this.relayUpdate );
126 - item.attach( this );
 118+ } else if ( parent ) {
 119+ parent.remove( item );
127120 }
 121+ this[this._listName].push( item );
 122+ item.on( 'update', this.relayUpdate );
 123+ item.attach( this );
128124 this.emit( 'append', item );
129125 this.emit( 'update' );
130126 };
@@ -141,16 +137,12 @@
142138 var parent = item.parent();
143139 if ( parent === this ) {
144140 this[this._listName].splice( this.indexOf( item ), 1 );
145 - this[this._listName].unshift( item );
146 - } else {
147 - if ( parent ) {
148 - parent.remove( item );
149 - }
150 - this[this._listName].unshift( item );
151 - var container = this;
152 - item.on( 'update', this.relayUpdate );
153 - item.attach( this );
 141+ } else if ( parent ) {
 142+ parent.remove( item );
154143 }
 144+ this[this._listName].unshift( item );
 145+ item.on( 'update', this.relayUpdate );
 146+ item.attach( this );
155147 this.emit( 'prepend', item );
156148 this.emit( 'update' );
157149 };
@@ -169,24 +161,16 @@
170162 var parent = item.parent();
171163 if ( parent === this ) {
172164 this[this._listName].splice( this.indexOf( item ), 1 );
173 - if ( before ) {
174 - this[this._listName].splice( this[this._listName].indexOf( before ), 0, item );
175 - } else {
176 - this[this._listName].unshift( item );
177 - }
 165+ } else if ( parent ) {
 166+ parent.remove( item );
 167+ }
 168+ if ( before ) {
 169+ this[this._listName].splice( this[this._listName].indexOf( before ), 0, item );
178170 } else {
179 - if ( parent ) {
180 - parent.remove( item );
181 - }
182 - if ( before ) {
183 - this[this._listName].splice( this[this._listName].indexOf( before ), 0, item );
184 - } else {
185 - this[this._listName].unshift( item );
186 - }
187 - var container = this;
188 - item.on( 'update', this.relayUpdate );
189 - item.attach( this );
 171+ this[this._listName].unshift( item );
190172 }
 173+ item.on( 'update', this.relayUpdate );
 174+ item.attach( this );
191175 this.emit( 'insertBefore', item, before );
192176 this.emit( 'update' );
193177 };
@@ -205,24 +189,16 @@
206190 var parent = item.parent();
207191 if ( parent === this ) {
208192 this[this._listName].splice( this.indexOf( item ), 1 );
209 - if ( after ) {
210 - this[this._listName].splice( this[this._listName].indexOf( after ) + 1, 0, item );
211 - } else {
212 - this[this._listName].push( item );
213 - }
 193+ } else if ( parent ) {
 194+ parent.remove( item );
 195+ }
 196+ if ( after ) {
 197+ this[this._listName].splice( this[this._listName].indexOf( after ) + 1, 0, item );
214198 } else {
215 - if ( parent ) {
216 - parent.remove( item );
217 - }
218 - if ( after ) {
219 - this[this._listName].splice( this[this._listName].indexOf( after ) + 1, 0, item );
220 - } else {
221 - this[this._listName].push( item );
222 - }
223 - var container = this;
224 - item.on( 'update', this.relayUpdate );
225 - item.attach( this );
 199+ this[this._listName].push( item );
226200 }
 201+ item.on( 'update', this.relayUpdate );
 202+ item.attach( this );
227203 this.emit( 'insertAfter', item, after );
228204 this.emit( 'update' );
229205 };
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
@@ -31,6 +31,9 @@
3232 }
3333 this.$.addClass( 'editSurface-' + typeName ).data( typeName, this );
3434 var container = this;
 35+ this.relayUpdate = function() {
 36+ container.emit( 'update' );
 37+ };
3538 function recycleItemView( itemModel, autoCreate ) {
3639 var itemView = container.lookupItemView( itemModel );
3740 if ( itemView ) {
@@ -44,6 +47,7 @@
4548 }
4649 this.containerModel.on( 'prepend', function( itemModel ) {
4750 var itemView = recycleItemView( itemModel, true );
 51+ itemView.on( 'update', container.relayUpdate );
4852 container.views.unshift( itemView );
4953 container.$.prepend( itemView.$ );
5054 container.emit( 'prepend', itemView );
@@ -51,6 +55,7 @@
5256 } );
5357 this.containerModel.on( 'append', function( itemModel ) {
5458 var itemView = recycleItemView( itemModel, true );
 59+ itemView.on( 'update', container.relayUpdate );
5560 container.views.push( itemView );
5661 container.$.append( itemView.$ );
5762 container.emit( 'append', itemView );
@@ -59,6 +64,7 @@
6065 this.containerModel.on( 'insertBefore', function( itemModel, beforeModel ) {
6166 var beforeView = container.lookupItemView( beforeModel ),
6267 itemView = recycleItemView( itemModel, true );
 68+ itemView.on( 'update', container.relayUpdate );
6369 if ( beforeView ) {
6470 container.views.splice( container.views.indexOf( beforeView ), 0, itemView );
6571 itemView.$.insertBefore( beforeView.$ );
@@ -72,6 +78,7 @@
7379 this.containerModel.on( 'insertAfter', function( itemModel, afterModel ) {
7480 var afterView = container.lookupItemView( afterModel ),
7581 itemView = recycleItemView( itemModel, true );
 82+ itemView.on( 'update', container.relayUpdate );
7683 if ( afterView ) {
7784 container.views.splice( container.views.indexOf( afterView ) + 1, 0, itemView );
7885 itemView.$.insertAfter( afterView.$ );
@@ -84,6 +91,7 @@
8592 } );
8693 this.containerModel.on( 'remove', function( itemModel ) {
8794 var itemView = recycleItemView( itemModel );
 95+ itemView.removeListener( 'update', container.relayUpdate );
8896 container.emit( 'remove', itemView );
8997 container.emit( 'update' );
9098 } );
Index: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
@@ -447,7 +447,7 @@
448448 .nextAll()
449449 .remove();
450450 rs.timeout = undefined;
451 - this.emit( 'render' );
 451+ this.emit( 'update' );
452452 } else {
453453 rs.ruler.innerHTML = '';
454454 var that = this;
@@ -494,7 +494,7 @@
495495 'wordOffset': 0,
496496 'fractional': false
497497 }];
498 - this.emit( 'render' );
 498+ this.emit( 'update' );
499499 return;
500500 }
501501 /*
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js
@@ -4,6 +4,10 @@
55 es.ParagraphBlockView = function( model ) {
66 es.BlockView.call( this, model, 'paragraph' );
77 this.contentView = new es.ContentView( this.$, this.model.content );
 8+ var view = this;
 9+ this.contentView.on( 'update', function() {
 10+ view.emit('update');
 11+ } );
812 };
913
1014 /**

Status & tagging log