Skip to content
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

Added Ember.computed.flattenArray #3503

Closed
wants to merge 1 commit into from

Conversation

@Nopik
Copy link
Contributor

commented Sep 30, 2013

Ember.computed.flattenArray proposal to allow computed flattenning of arrays. E.g.:

var item1 = Ember.Object.create({
  tags: [ 'important', 'bug', 'task' ],
});

var item2 = Ember.Object.create({
  tags: [ 'urgent', 'feature', 'task' ],
});

App.ItemList = Ember.ArrayProxy.extend({
  allTags: Ember.computed.flattenArray( 'content', 'tags' )
});

var myList = App.ItemList.create({ content: [ item1, item2 ] });
myList.get( 'allTags' );
// -> ["important", "bug", "task", "urgent", "feature", "task"]
@bradleypriest

This comment has been minimized.

Copy link
Member

commented Oct 1, 2013

Hi @Nopik I think this is probably a little specific for Ember Core, however, check out and submit it over at https://github.com/jamesarosen/ember-cpm.

@wycats

This comment has been minimized.

Copy link
Member

commented Oct 2, 2013

I agree with @bradleypriest. Community-maintained extensions are great though!

@wycats wycats closed this Oct 2, 2013

@fwoeck

This comment has been minimized.

Copy link
Contributor

commented Jan 5, 2014

I'd love to see this in core - that's pretty common with array aggregation.

@probablyup

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2014

@fwoeck Is there any real performance difference between making this a macro, versus doing something like this?

allTags: Ember.computed(function(){
    return [].concat( this.get('content'), this.get('tags') );
}).property('content.[]', 'tags.[]')

I agree with @bradleypriest that this seems overly specific.

@stefanpenner

This comment has been minimized.

Copy link
Member

commented Jan 6, 2014

@3lux yes, the macro only operates on what changed.

@fwoeck

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2014

@stefanpenner thanks for the comment - I was looking for that information. That's a noob question, but the "one-at-a-time" semantics stem from the addedItem/removedItem-functions right?

@stefanpenner

This comment has been minimized.

Copy link
Member

commented Jan 6, 2014

ya, and much internal magic by señor @hjdivad to make it nice and performant. The TL;DR is the reduce computer and array computed macros aim to reduce churn when data changes. It does so by attempted to do the smallest amount of work possible to transform arrays.

@hjdivad

This comment has been minimized.

Copy link
Member

commented Jan 6, 2014

@mmpestorich

This comment has been minimized.

Copy link
Contributor

commented Jan 13, 2014

I'd like to see this in core as well. In glancing through some our apps I see a few places that this it would get used.

@alvincrespo

This comment has been minimized.

Copy link
Contributor

commented Jan 31, 2014

👍 This is something I believe would be extremely helpful in the core. We've found that this has to be done quite a bit to provide the kind of "flat" UX needed without having to adjust our Models relationships.

Is there reason why we wouldn't want it in the core?

@jasonmit

This comment has been minimized.

Copy link
Member

commented Feb 1, 2014

I also would like to see this in core. It's a common pattern and I figure the vast majority of developers would do the @3lux approach (no offense - it's what I would have done :)

@kumavis

This comment has been minimized.

Copy link
Contributor

commented May 12, 2014

I feel like this is a fundamental tool in data flow programming, so I'm surprised its not included in core.

teams.flatMap('members').uniq()
(but for Computed Array props)

@cibernox

This comment has been minimized.

Copy link
Contributor

commented May 13, 2014

I also vote for core. Flatten is part of the stdlib of a lot of languages, so with the same analogy, I think that being in the core is ok.

@alvincrespo

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2014

👍 Upvoting again :)

@fwoeck

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2014

Hi guys (@bradleypriest, @wycats, @stefanpenner), would you reconsider your previous decision and tell us what you think?

@mellatone

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2014

Upvote for flattenArray

@bgentry

This comment has been minimized.

Copy link
Contributor

commented Feb 22, 2015

I definitely agree that this would be useful to include in Ember. This is especially non-trivial when you're trying to flatten multiple levels of hasMany associations in ember-data. For example, consider trying to fetch all of an Artist's Songs when only their Albums are directly associated.

Is there a 3rd party solution for that sort of thing?

@stefanpenner

This comment has been minimized.

Copy link
Member

commented Feb 22, 2015

Hi guys (@bradleypriest, @wycats, @stefanpenner), would you reconsider your previous decision and tell us what you think?

this still feels like a great community add-on.

@jrjohnson

This comment has been minimized.

Copy link

commented Mar 8, 2015

@Nopik - are you willing to create a pull request to add this to ember-cpm - or would you mind someone else doing that with your code?

@stefanpenner

This comment has been minimized.

Copy link
Member

commented Mar 9, 2015

@Nopik - are you willing to create a pull request to add this to ember-cpm - or would you mind someone else doing that with your code?

👍

@Nopik

This comment has been minimized.

Copy link
Contributor Author

commented Mar 9, 2015

Go ahead and create the pull request. I wasn't working with ember-cpm at all, and stopped using Ember over a half year ago, so you probably will do that better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.