-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flat representation through embedded arrays #440
Comments
Hello @aalbul. To do so, you can either rely on raw JavaScript array methods such as Using raw JavaScript var names = tree.get('hosts')
// Here we recursively retrieve the name of each deployed
// This will produce something like the following:
// [['name1', 'name2'], ['name3', 'name4']]
.map(function(host) {
return host.deployeds.map(function(deployed) {
return deployed.name
});
})
// So now we need to flatten the result to obtain:
// ['name1', 'name2', 'name3', 'name4']
.reduce(function(acc, names) {
return acc.concat(names);
}, []); Using lodash var names = _(tree.get('hosts'))
.map(function(host) {
return _.map(host, 'name');
})
.flatten()
.value(); Also know that if this is something you might want to do often in your code, you can also consider creating a monkey that will hold this computed data for you. |
Hi @Yomguithereal and thank you for your answer.
The output will look like:
The idea is to settle monkeys on every "host" node so it can cache the results within it and then to settle a monkey within a global object so it will cache results of the host's monkeys. And as you see, It works. However i'm not really happy with implementation:
|
Oh i spend so much time thinking about the title for this issue.
Let me show you an example so it will explain it better.
Let's assume that i have a tree like this:
Now, i would like to select a list of all deployed names.
I'm trying to do something like:
console.log(tree.select('hosts', 'deployeds', 'name').get());
But, off course getting "undeffined". The reason, i suppose, is that selector tries to get a field 'deployeds' from of 'hosts' array field and, off course it fails.
Is there are any way to do the query like that? (In an elegant way :))
The text was updated successfully, but these errors were encountered: