Debounce reference list updates

Ideally update wouldn't be called multiple times
for simple transactions, but this should prevent
unnecessary updates if that does happen.

Bug: T176066
Change-Id: I1e7a21c19cee7d50ca160749f243c57f2fb08bab
This commit is contained in:
Ed Sanders 2017-09-18 13:06:44 +01:00 committed by Divec
parent 7f7206adda
commit a024a7d2c6

View file

@ -36,8 +36,10 @@ ve.ce.MWReferencesListNode = function VeCeMWReferencesListNode() {
// Events // Events
this.model.connect( this, { attributeChange: 'onAttributeChange' } ); this.model.connect( this, { attributeChange: 'onAttributeChange' } );
this.updateDebounced = ve.debounce( this.update.bind( this ) );
// Initialization // Initialization
this.update(); this.updateDebounced();
}; };
/* Inheritance */ /* Inheritance */
@ -108,7 +110,7 @@ ve.ce.MWReferencesListNode.prototype.onTeardown = function () {
ve.ce.MWReferencesListNode.prototype.onInternalListUpdate = function ( groupsChanged ) { ve.ce.MWReferencesListNode.prototype.onInternalListUpdate = function ( groupsChanged ) {
// Only update if this group has been changed // Only update if this group has been changed
if ( groupsChanged.indexOf( this.model.getAttribute( 'listGroup' ) ) !== -1 ) { if ( groupsChanged.indexOf( this.model.getAttribute( 'listGroup' ) ) !== -1 ) {
this.update(); this.updateDebounced();
} }
}; };
@ -121,7 +123,7 @@ ve.ce.MWReferencesListNode.prototype.onInternalListUpdate = function ( groupsCha
*/ */
ve.ce.MWReferencesListNode.prototype.onAttributeChange = function ( key ) { ve.ce.MWReferencesListNode.prototype.onAttributeChange = function ( key ) {
if ( key === 'listGroup' ) { if ( key === 'listGroup' ) {
this.update(); this.updateDebounced();
} }
}; };
@ -136,7 +138,7 @@ ve.ce.MWReferencesListNode.prototype.onListNodeUpdate = function () {
// When the list node updates we're not sure which list group the item // When the list node updates we're not sure which list group the item
// belonged to so we always update // belonged to so we always update
// TODO: Only re-render the reference which has been edited // TODO: Only re-render the reference which has been edited
this.update(); this.updateDebounced();
}; };
/** /**