r104107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104106‎ | r104107 | r104108 >
Date:23:42, 23 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added time-buffer to emitting updates
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -27,6 +27,7 @@
2828 this.$cursor = $( '<div class="es-surfaceView-cursor"></div>' )
2929 .appendTo( this.$ );
3030 this.updateSelectionTimeout = undefined;
 31+ this.emitUpdateTimeoue = undefined;
3132
3233 // Interaction states
3334
@@ -72,9 +73,9 @@
7374 _this.updateSelection( 0 );
7475 } );
7576 this.model.getDocument().on( 'update', function() {
76 - _this.emit( 'update' );
 77+ _this.emitUpdate( 25 );
7778 // Respond to layout changes
78 - _this.updateSelection( 50 );
 79+ _this.updateSelection( 25 );
7980 } );
8081 this.$.mousedown( function(e) {
8182 return _this.onMouseDown( e );
@@ -153,9 +154,20 @@
154155 _this.documentView.clearSelection( _this.currentSelection );
155156 }
156157 _this.updateSelectionTimeout = undefined;
157 - }, delay );
 158+ }, delay || 0 );
158159 };
159160
 161+es.SurfaceView.prototype.emitUpdate = function( delay ) {
 162+ if ( this.emitUpdateTimeout !== undefined ) {
 163+ return;
 164+ }
 165+ var _this = this;
 166+ this.emitUpdateTimeout = setTimeout( function() {
 167+ _this.emit( 'update' );
 168+ _this.emitUpdateTimeout = undefined;
 169+ }, delay || 0 );
 170+};
 171+
160172 es.SurfaceView.prototype.onMouseDown = function( e ) {
161173 // Only for left mouse button
162174 if ( e.button === 0 ) {

Status & tagging log