http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96698

Revision: 96698
Author:   inez
Date:     2011-09-09 21:53:29 +0000 (Fri, 09 Sep 2011)
Log Message:
-----------
Cleanup for event emitters and subscribers

Modified Paths:
--------------
    trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js
    trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
    trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
    trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js
    trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js
    trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
    trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js

Modified: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js  2011-09-09 
21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/bases/es.ModelContainer.js  2011-09-09 
21:53:29 UTC (rev 96698)
@@ -114,16 +114,12 @@
        var parent = item.parent();
        if ( parent === this ) {
                this[this._listName].splice( this.indexOf( item ), 1 );
-               this[this._listName].push( item );
-       } else {
-               if ( parent ) {
-                       parent.remove( item );
-               }
-               this[this._listName].push( item );
-               var container = this;
-               item.on( 'update', this.relayUpdate );
-               item.attach( this );
+       } else if ( parent ) {
+               parent.remove( item );
        }
+       this[this._listName].push( item );
+       item.on( 'update', this.relayUpdate );
+       item.attach( this );
        this.emit( 'append', item );
        this.emit( 'update' );
 };
@@ -141,16 +137,12 @@
        var parent = item.parent();
        if ( parent === this ) {
                this[this._listName].splice( this.indexOf( item ), 1 );
-               this[this._listName].unshift( item );
-       } else {
-               if ( parent ) {
-                       parent.remove( item );
-               }
-               this[this._listName].unshift( item );
-               var container = this;
-               item.on( 'update', this.relayUpdate );
-               item.attach( this );
+       } else if ( parent ) {
+               parent.remove( item );
        }
+       this[this._listName].unshift( item );
+       item.on( 'update', this.relayUpdate );
+       item.attach( this );
        this.emit( 'prepend', item );
        this.emit( 'update' );
 };
@@ -169,24 +161,16 @@
        var parent = item.parent();
        if ( parent === this ) {
                this[this._listName].splice( this.indexOf( item ), 1 );
-               if ( before ) {
-                       this[this._listName].splice( 
this[this._listName].indexOf( before ), 0, item );
-               } else {
-                       this[this._listName].unshift( item );
-               }
+       } else if ( parent ) {
+               parent.remove( item );
+       }
+       if ( before ) {
+               this[this._listName].splice( this[this._listName].indexOf( 
before ), 0, item );
        } else {
-               if ( parent ) {
-                       parent.remove( item );
-               }
-               if ( before ) {
-                       this[this._listName].splice( 
this[this._listName].indexOf( before ), 0, item );
-               } else {
-                       this[this._listName].unshift( item );
-               }
-               var container = this;
-               item.on( 'update', this.relayUpdate );
-               item.attach( this );
+               this[this._listName].unshift( item );
        }
+       item.on( 'update', this.relayUpdate );
+       item.attach( this );
        this.emit( 'insertBefore', item, before );
        this.emit( 'update' );
 };
@@ -205,24 +189,16 @@
        var parent = item.parent();
        if ( parent === this ) {
                this[this._listName].splice( this.indexOf( item ), 1 );
-               if ( after ) {
-                       this[this._listName].splice( 
this[this._listName].indexOf( after ) + 1, 0, item );
-               } else {
-                       this[this._listName].push( item );
-               }
+       } else if ( parent ) {
+               parent.remove( item );
+       }
+       if ( after ) {
+               this[this._listName].splice( this[this._listName].indexOf( 
after ) + 1, 0, item );
        } else {
-               if ( parent ) {
-                       parent.remove( item );
-               }
-               if ( after ) {
-                       this[this._listName].splice( 
this[this._listName].indexOf( after ) + 1, 0, item );
-               } else {
-                       this[this._listName].push( item );
-               }
-               var container = this;
-               item.on( 'update', this.relayUpdate );
-               item.attach( this );
+               this[this._listName].push( item );
        }
+       item.on( 'update', this.relayUpdate );
+       item.attach( this );
        this.emit( 'insertAfter', item, after );
        this.emit( 'update' );
 };

Modified: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js   2011-09-09 
21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js   2011-09-09 
21:53:29 UTC (rev 96698)
@@ -31,6 +31,9 @@
        }
        this.$.addClass( 'editSurface-' + typeName ).data( typeName, this );
        var container = this;
+       this.relayUpdate = function() {
+               container.emit( 'update' );
+       };
        function recycleItemView( itemModel, autoCreate ) {
                var itemView = container.lookupItemView( itemModel );
                if ( itemView ) {
@@ -44,6 +47,7 @@
        }
        this.containerModel.on( 'prepend', function( itemModel ) {
                var itemView = recycleItemView( itemModel, true );
+               itemView.on( 'update', container.relayUpdate );
                container.views.unshift( itemView );
                container.$.prepend( itemView.$ );
                container.emit( 'prepend', itemView );
@@ -51,6 +55,7 @@
        } );
        this.containerModel.on( 'append', function( itemModel ) {
                var itemView = recycleItemView( itemModel, true );
+               itemView.on( 'update', container.relayUpdate );
                container.views.push( itemView );
                container.$.append( itemView.$ );
                container.emit( 'append', itemView );
@@ -59,6 +64,7 @@
        this.containerModel.on( 'insertBefore', function( itemModel, 
beforeModel ) {
                var beforeView = container.lookupItemView( beforeModel ),
                        itemView = recycleItemView( itemModel, true );
+               itemView.on( 'update', container.relayUpdate );
                if ( beforeView ) {
                        container.views.splice( container.views.indexOf( 
beforeView ), 0, itemView );
                        itemView.$.insertBefore( beforeView.$ );
@@ -72,6 +78,7 @@
        this.containerModel.on( 'insertAfter', function( itemModel, afterModel 
) {
                var afterView = container.lookupItemView( afterModel ),
                        itemView = recycleItemView( itemModel, true );
+               itemView.on( 'update', container.relayUpdate );
                if ( afterView ) {
                        container.views.splice( container.views.indexOf( 
afterView ) + 1, 0, itemView );
                        itemView.$.insertAfter( afterView.$ );
@@ -84,6 +91,7 @@
        } );
        this.containerModel.on( 'remove', function( itemModel ) {
                var itemView = recycleItemView( itemModel );
+               itemView.removeListener( 'update', container.relayUpdate );
                container.emit( 'remove', itemView );
                container.emit( 'update' );
        } );

Modified: trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js   2011-09-09 
21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/models/es.ContentModel.js   2011-09-09 
21:53:29 UTC (rev 96698)
@@ -433,7 +433,7 @@
                'offset': offset,
                'content': content
        } );
-       this.emit( 'change', { 'type': 'insert' } );
+       this.emit( 'update', { 'type': 'insert' } );
 };
 
 /**
@@ -450,7 +450,7 @@
        this.emit( 'remove', {
                'range': range
        } );
-       this.emit( 'change', { 'type': 'remove' } );
+       this.emit( 'update', { 'type': 'remove' } );
 };
 
 /**
@@ -463,7 +463,7 @@
 es.ContentModel.prototype.clear = function() {
        this.data = [];
        this.emit( 'clear' );
-       this.emit( 'change', { 'type': 'clear' } );
+       this.emit( 'update', { 'type': 'clear' } );
 };
 
 /**
@@ -568,7 +568,7 @@
                'annotation': annotation,
                'range': range
        } );
-       this.emit( 'change', { 'type': 'annotate' } );
+       this.emit( 'update', { 'type': 'annotate' } );
 };
 
 es.extend( es.ContentModel, es.EventEmitter );

Modified: trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js 2011-09-09 
21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/models/es.ListBlockModel.js 2011-09-09 
21:53:29 UTC (rev 96698)
@@ -9,7 +9,11 @@
 es.ListBlockModel = function( items ) {
        es.BlockModel.call( this, ['hasContent', 'isAnnotatable', 
'isAggregate'] );
        es.ModelContainer.call( this );
-       this.items = new es.AggregateArray( items || [] );
+       if ( $.isArray( items ) ) {
+               for ( var i = 0; i < items.length; i++ ) {
+                       this.append( items[i] );
+               }
+       }
 };
 
 /* Static Methods */

Modified: trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js    
2011-09-09 21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js    
2011-09-09 21:53:29 UTC (rev 96698)
@@ -8,7 +8,11 @@
  */
 es.ParagraphBlockModel = function( content ) {
        es.BlockModel.call( this, ['hasContent', 'isAnnotatable'] );
-       this.content = content || null;
+       this.content = content || new es.ContentModel();
+       var model = this;
+       this.content.on( 'change', function() {
+               model.emit( 'update' );
+       } );
 };
 
 /* Static Methods */

Modified: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.ContentView.js     2011-09-09 
21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/views/es.ContentView.js     2011-09-09 
21:53:29 UTC (rev 96698)
@@ -447,7 +447,7 @@
                        .nextAll()
                        .remove();
                rs.timeout = undefined;
-               this.emit( 'render' );
+               this.emit( 'update' );
        } else {
                rs.ruler.innerHTML = '';
                var that = this;
@@ -494,7 +494,7 @@
                        'wordOffset': 0,
                        'fractional': false
                }];
-               this.emit( 'render' );
+               this.emit( 'update' );
                return;
        }
        /*

Modified: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js      
2011-09-09 21:25:21 UTC (rev 96697)
+++ trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js      
2011-09-09 21:53:29 UTC (rev 96698)
@@ -4,6 +4,10 @@
 es.ParagraphBlockView = function( model ) {
        es.BlockView.call( this, model, 'paragraph' );
        this.contentView = new es.ContentView( this.$, this.model.content );
+       var view = this;
+       this.contentView.on( 'update', function() {
+               view.emit('update');
+       } );
 };
 
 /**


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to