From 0a50b22496fc619fe075c61fe618ffdb9816aa10 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 9 Feb 2018 11:03:21 -0500 Subject: [PATCH] Cmatch: Extract show/hide marking into own method This is to give us a fairly easy means of testing this logic for a bugfix. This refactoring also obviates a pretty nasty bug; see docblock. * src/client/Cmatch.js (_handleClassMatch): Extract show/hide marking. (markShowHide): New method. --- src/client/Cmatch.js | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/client/Cmatch.js b/src/client/Cmatch.js index 5766da3..62913c6 100644 --- a/src/client/Cmatch.js +++ b/src/client/Cmatch.js @@ -300,17 +300,7 @@ module.exports = Class( 'Cmatch', ( ( vis[ i ] ) ? show : hide ).push( i ); } - if ( show.length ) - { - visq[ field ] = { event_id: 'show', name: field, indexes: show }; - this._mergeCmatchHidden( field, show, false ); - } - - if ( hide.length ) - { - visq[ field ] = { event_id: 'hide', name: field, indexes: hide }; - this._mergeCmatchHidden( field, hide, true ); - } + this.markShowHide( field, visq, show, hide ); } // it's important to do this before showing/hiding fields, since @@ -339,6 +329,41 @@ module.exports = Class( 'Cmatch', }, + /** + * Mark fields to be shown/hidden + * + * This also updates the cached visibility of field FIELD. + * + * XXX: This method makes very obvious a nasty bug where hides override + * shows if both are set. + * + * @param {string} field field name + * @param {Array} show indexes to show + * @param {Array} hide indexes to hide + * + * @return {undefined} + */ + 'protected markShowHide'( field, visq, show, hide ) + { + if ( !( show.length || hide.length ) ) + { + return; + } + + if ( show.length ) + { + this._mergeCmatchHidden( field, show, false ); + visq[ field ] = { event_id: 'show', name: field, indexes: show }; + } + + if ( hide.length ) + { + this._mergeCmatchHidden( field, hide, true ); + visq[ field ] = { event_id: 'hide', name: field, indexes: hide }; + } + }, + + /** * Trigger DataApi event for field FIELD *