From 9066e5b89b83b8065babd4a7f6a934a7d4e00f50 Mon Sep 17 00:00:00 2001 From: Tony Wu Date: Thu, 18 Apr 2024 17:01:25 +0100 Subject: [PATCH] ID-3779 Ensures Fliplet.DynamicContainer getters work --- js/build.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/js/build.js b/js/build.js index dda828d..a9d6f4c 100644 --- a/js/build.js +++ b/js/build.js @@ -44,23 +44,21 @@ }); }); - Fliplet.DynamicContainer.get = function(name, options) { + Fliplet.DynamicContainer.get = function(filter, options) { + if (typeof filter !== 'object' || typeof filter !== 'function') { + filter = { id: filter }; + } + options = options || { ts: 10 }; return Fliplet().then(function() { return Promise.all(Object.values(dynamicContainerInstances)).then(function(containers) { var container; - if (typeof name === 'undefined') { + if (typeof filter === 'undefined') { container = containers.length ? containers[0] : undefined; } else { - containers.some(function(vm) { - if (vm.name === name) { - container = vm; - - return true; - } - }); + container = _.find(containers, filter); } if (!container) { @@ -73,7 +71,7 @@ setTimeout(function() { options.ts = options.ts * 1.5; - Fliplet.DynamicContainer.get(name, options).then(resolve); + Fliplet.DynamicContainer.get(filter, options).then(resolve); }, options.ts); }); } @@ -83,16 +81,18 @@ }); }; - Fliplet.DynamicContainer.getAll = function(name) { + Fliplet.DynamicContainer.getAll = function(filter) { + if (typeof filter !== 'object' || typeof filter !== 'function') { + filter = { id: filter }; + } + return Fliplet().then(function() { return Promise.all(Object.values(dynamicContainerInstances)).then(function(containers) { - if (typeof name === 'undefined') { + if (typeof filter === 'undefined') { return containers; } - return containers.filter(function(form) { - return form.name === name; - }); + return _.filter(containers, filter); }); }); };