Skip to content

Commit

Permalink
ID-3779 Ensures Fliplet.DynamicContainer getters work
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytlwu committed Apr 18, 2024
1 parent 8fc99a8 commit 9066e5b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
});
}
Expand All @@ -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);
});
});
};
Expand Down

0 comments on commit 9066e5b

Please sign in to comment.