Flattening an Array

I would like to propose that a utility in Ember.ArrayProxy be created to flatten nested arrays.

Similar to this gist by Mehul Kar, I’ve run into many situations that require multi-level relationships to be flattened in order to provide a better user experience. By implementing the flatten utility into the Ember library we can help eliminate custom solutions and confusion when it comes to working with Array’s, including PromiseArray and ManyArray in Ember Data.

Thoughts? Opinions?

1 Like

This might be better done as a computed property. We can create a collection of computed properties that can be reused. If some become popular, then we can propose them to go into the core.

Would this work for you?

This was brought forward as a PR a few months back but rejected into core for being a little too specific.

https://github.com/emberjs/ember.js/pull/3503

@tarasm Sounds like a good idea. Although I’m not familiar with using the computed properties to accomplish this. Is there more documentation on Ember.Computed?

You’re probably better off using this guys computed rather than reinventing the wheel. Added Ember.computed.flattenArray by Nopik · Pull Request #3503 · emberjs/ember.js · GitHub

1 Like

Here you are for people who land here!

Ember Composable Helpers also has flatten, map, and map-by.