Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/306967
Change subject: Remove items from DTH factory caches when unregistering ...................................................................... Remove items from DTH factory caches when unregistering Bug: T143954 Change-Id: I4a5a5de4dbd234f752f0111b086f2e63dec43ba2 --- M src/ui/ve.ui.DataTransferHandlerFactory.js 1 file changed, 47 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/67/306967/1 diff --git a/src/ui/ve.ui.DataTransferHandlerFactory.js b/src/ui/ve.ui.DataTransferHandlerFactory.js index 1b649e4..d4116db 100644 --- a/src/ui/ve.ui.DataTransferHandlerFactory.js +++ b/src/ui/ve.ui.DataTransferHandlerFactory.js @@ -33,14 +33,30 @@ * @inheritdoc */ ve.ui.DataTransferHandlerFactory.prototype.register = function ( constructor ) { - var i, j, ilen, jlen, kinds, types, extensions; - // Parent method - ve.ui.DataTransferHandlerFactory.super.prototype.register.call( this, constructor ); + ve.ui.DataTransferHandlerFactory.super.prototype.register.apply( this, arguments ); - kinds = constructor.static.kinds; - types = constructor.static.types; - extensions = constructor.static.extensions; + this.updateIndexes( constructor, true ); +}; + +/** + * @inheritdoc + */ +ve.ui.DataTransferHandlerFactory.prototype.unregister = function ( constructor ) { + // Parent method + ve.ui.DataTransferHandlerFactory.super.prototype.unregister.apply( this, arguments ); + + this.updateIndexes( constructor, false ); +}; + +/** + * @inheritdoc + */ +ve.ui.DataTransferHandlerFactory.prototype.updateIndexes = function ( constructor, insert ) { + var i, j, ilen, jlen, + kinds = constructor.static.kinds, + types = constructor.static.types, + extensions = constructor.static.extensions; function ensureArray( obj, prop ) { if ( obj[ prop ] === undefined ) { @@ -56,23 +72,42 @@ return obj[ prop ]; } + function remove( arr, item ) { + var index; + if ( ( index = arr.indexOf( item ) ) !== -1 ) { + arr.splice( index, 1 ); + } + } + if ( !kinds ) { for ( j = 0, jlen = types.length; j < jlen; j++ ) { - ensureArray( this.handlerNamesByType, types[ j ] ).unshift( constructor.static.name ); + if ( insert ) { + ensureArray( this.handlerNamesByType, types[ j ] ).unshift( constructor.static.name ); + } else { + remove( this.handlerNamesByType[ types[ j ] ], constructor.static.name ); + } } } else { for ( i = 0, ilen = kinds.length; i < ilen; i++ ) { for ( j = 0, jlen = types.length; j < jlen; j++ ) { - ensureArray( - ensureMap( this.handlerNamesByKindAndType, kinds[ i ] ), - types[ j ] - ).unshift( constructor.static.name ); + if ( insert ) { + ensureArray( + ensureMap( this.handlerNamesByKindAndType, kinds[ i ] ), + types[ j ] + ).unshift( constructor.static.name ); + } else { + remove( this.handlerNamesByKindAndType[ kinds[ i ] ][ types[ j ] ], constructor.static.name ); + } } } } if ( constructor.prototype instanceof ve.ui.FileTransferHandler ) { for ( i = 0, ilen = extensions.length; i < ilen; i++ ) { - ensureArray( this.handlerNamesByExtension, extensions[ i ] ).unshift( constructor.static.name ); + if ( insert ) { + ensureArray( this.handlerNamesByExtension, extensions[ i ] ).unshift( constructor.static.name ); + } else { + remove( this.handlerNamesByExtension[ extensions[ i ] ], constructor.static.name ); + } } } }; -- To view, visit https://gerrit.wikimedia.org/r/306967 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4a5a5de4dbd234f752f0111b086f2e63dec43ba2 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits