diff --git a/static/js/services/utilRegistry.js b/static/js/services/utilRegistry.js index a73b914bf..4ffdada2f 100644 --- a/static/js/services/utilRegistry.js +++ b/static/js/services/utilRegistry.js @@ -106,8 +106,25 @@ } function _destroyUtilInstances(name) { - console.log('TODO: destroy util instances', { name }); - // call destroy on each activeUtilInstance that matches the name + activeUtilInstances + .map(function(util, index) { + return { + util: util, + index: index, + }; + }).filter(function(activeUtil) { + // find utils instances to destroy + return activeUtil.util.name === name; + }).forEach(function(activeUtil) { + // destroy util instance + activeUtil.util.destroy(); + delete activeUtilInstances[activeUtil.index]; + }); + + // get rid of now empty array slots + activeUtilInstances = activeUtilInstances.filter(function(util) { + return !!util; + }) } // public API