Skip to content

Commit

Permalink
Merge pull request #3 from Fliplet/feature/ID-3779
Browse files Browse the repository at this point in the history
ID-3779 [Feature] Ensures Fliplet.DynamicContainer getters work
  • Loading branch information
tonytlwu authored Apr 18, 2024
2 parents 8fc99a8 + 9066e5b commit ab1a88d
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 ab1a88d

Please sign in to comment.