From 04d0f19d9cc3d16f609b7bcf28a3e123f98c1dd2 Mon Sep 17 00:00:00 2001 From: Felix Hamann Date: Wed, 10 Apr 2019 22:51:03 +0200 Subject: [PATCH] implement destroy util function in js utility registry --- static/js/services/utilRegistry.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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