Skip to content

Ember.Arrangable mixin (SortableMixin + FilterableMixin) - #1562

Closed
ahawkins wants to merge 18 commits into
emberjs:masterfrom
ahawkins:arrangable-mixin
Closed

ahawkins wants to merge 18 commits into
emberjs:masterfrom
ahawkins:arrangable-mixin

Conversation

@ahawkins

Copy link
Copy Markdown

This PR take commits from #1288 and combines that with the existing SortableMixin. This makes it easier to use both at the same time. It also should be more performant in the combined use case because it does not have to loop over the content array twice to add observers. The existing api from Ember.SortableMixin is mirrored for filtering. You can specify filterProperties the same as sortProperties.

There is one failing test ATM. The test is carried over from the Ember.SortableMixin and the other PR. I've added more tests around filtering and sorting the same array.

I've pushed this code to say that I'm serious about this feature. This is a major pain point of us. I can't see why there can't be one single mixin to do this.

The original implementation is from @crofty. I've simply pulled his commits and refactored them so they can be merged with Ember.SortableMixin.

Edit: I've realized that I completely suck at spelling and/or typing.

@wagenet

wagenet commented Dec 1, 2012

Copy link
Copy Markdown
Member

@twinturbo What's the status of this? I know you wanted to add some more filtering functionality. Also, I'm thinking that it probably wouldn't hurt to add the following just so we don't get people complaining:

Ember.SortableMixin = Ember.Mixin.create(Ember.ArrangeableMixin, {
  init: function() {
    Ember.deprecate("Ember.SortableMixin has been replaced by Ember.ArrangeableMixin.");
    this._super();
  }
});

@ahawkins

ahawkins commented Dec 1, 2012

Copy link
Copy Markdown
Author

I've added all the functionality I want. I just need to add docs and the
deprecation you suggested.
On Dec 1, 2012 7:08 PM, "Peter Wagenet" [email protected] wrote:

@twinturbo https://github.com/twinturbo What's the status of this? I
know you wanted to add some more filtering functionality. Also, I'm
thinking that it probably wouldn't hurt to add the following just so we
don't get people complaining:

Ember.SortableMixin = Ember.Mixin.create(Ember.ArrangeableMixin, {
init: function() {
Ember.deprecate("Ember.SortableMixin has been replaced by Ember.ArrangeableMixin.");
this._super();
}});

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1562#issuecomment-10919987.

@crofty

crofty commented Dec 1, 2012

Copy link
Copy Markdown
Contributor

@twinturbo there is currently a failing test in the sortable mixin (see #1537), can you add this test to this PR?

@ahawkins

ahawkins commented Dec 1, 2012

Copy link
Copy Markdown
Author

@crofty will do.

@ahawkins

ahawkins commented Dec 1, 2012

Copy link
Copy Markdown
Author

@wagenet I've added your deprecation fix. @tchak helped me come up with a better interface for filtering expressed ine 2780bc1. Now I just need to add docs and fix @crofty's failing test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to support the following example:

filterProperties: [['isNew', false]]

I think that it is as follows:

if (arguments.length === 3) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ursm what do you mean? Your comment confuses me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twinturbo I'm sorry for an ambiguous comment. It was fixed by ahawkins@ebe0337. Great works!

@ahawkins

Copy link
Copy Markdown
Author

@wagenet this is approaching completeness. Can you confer with the core team?

@leepfrog

Copy link
Copy Markdown

👍 works great for me

@wagenet

wagenet commented Dec 14, 2012

Copy link
Copy Markdown
Member

@twinturbo Github is reporting that it can't be merged automatically. Can you look into this?

crofty and others added 18 commits December 14, 2012 18:49
Works in a similar way to the SortableMixin.

Mix this into an ArrayProxy, define the filterProperties and the array
will be filtered to only include the objects whose filterProperties are
truthy.

You can get more advanced filtering by defining a custom
filterCondition. The filterCondition is used to determine if the object is
to be included in the filtered list.  Any item properties used in
the filterCondition will need to be lised in filterProperties.
These verify that the FilterableMixin works with bound content and updates correctly when the content is swapped out.
filterFunction can be overridden to correctly process
any object/key/value pair.

This commit also removes some duplicate tests
@ahawkins

Copy link
Copy Markdown
Author

@wagenet let me know what you think should be documented. I documented the main public parts. IDK what to do about the private stuff.

@tomdale

tomdale commented Dec 14, 2012

Copy link
Copy Markdown
Member

Hey @twinturbo, thanks for all of your hard work on this. @igorT has a proposal for handling this problem that allows it to be composed quite nicely. We've asked him to post his thoughts here to discuss how we can unify the efforts.

@ahawkins

Copy link
Copy Markdown
Author

@tomdale thanks for the update. I'll hang tight until then.

@ryanflorence

Copy link
Copy Markdown

just ran into this, can't wait for a nicer solution than copy pasta 💩

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twinturbo it would be nice to add support for passing the key into sortFunction. The sortFunction is somewhat useless if you have multiple sortProperties that are the same data type.

sortFunction(get(item1, propertyName), get(item2, propertyName),propertyName);

@igorT

igorT commented Dec 19, 2012

Copy link
Copy Markdown
Member

I thought about this for a while, and while I need to write a detailed spec/code it up here are some of my thoughts. It seems bad that we need a special mixin just because Sortable and Filterable do not play nice together. This is actually a symptom of a deeper problem, that the ArrayProxy API is not designed to be used by multiple mixins.

Even if we were to accept the Arrangeable mixin as a special case, we run into the same problem once somebody wants to extend it and modify it, either by changing the arrangedContent or just trying to mix in another ArrayProxy mixin. The way forward IMO would be to extend ArrayProxy API with several methods/properties and use those to desing a Sortable/Filterable, such that they both can be applied at the same time.

The main problem right now are the contentArrayWillChange and contentArrayDidChange methods, as they assume they operate on a continuous selection of items, which breaks if you want to do a sort and then call _super() and pass it to you parent method which might be one from filterable. Making new methods that act on a element, index pair would work a lot better.

You could then imagine having a filterable which simply decides whether or not to call _super() for a particular element and actually insert it, and a sortable that calls _super() with the new index. You would also need to extend arrangedContent and propagate initial setup there as well.

With this approach you can then easily have something like ArrayProxy.extends(Sortable, Filterable, Reversable, SomethingElsable, myOwnProxy), instead of having special cases.

I might have time to spike this during the holidays.

@wagenet wagenet mentioned this pull request Dec 19, 2012
@leepfrog

Copy link
Copy Markdown

Question from this morning... what is "Arrangable"?

@michaelbaudino

Copy link
Copy Markdown

@leepfrog a typo error :-) See abbc11a

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twinturbo discussed w/ @wycats @tomdale this AM. You're observing items in the array and needlessly recaulcuating while constructing the arrangableContent. It eventually finishes, but is highly inefficient.

We monkeypatched my running instance by copying off content to origContent and then moved this forEach below L#156

@ahawkins

Copy link
Copy Markdown
Author

@igorT anything so far?

@leepfrog

leepfrog commented Jan 4, 2013

Copy link
Copy Markdown

@igorT 👍 would be interested in seeing what you come up with as well. We're using ArrangableMixin and functionally it's great, but architecturally there are some issues that could use some ❤️ (eg: observer problem mentioned above).

@ahawkins

ahawkins commented Jan 4, 2013

Copy link
Copy Markdown
Author

@leepforg ill take care of that. Should be an easy fix.
On Jan 4, 2013 11:52 PM, "Andy Leeper" [email protected] wrote:

@igorT https://github.com/igorT [image: 👍] would be interested in
seeing what you come up with as well. We're using ArrangableMixin and
functionally it's great, but architecturally there are some issues that
could use some [image: ❤️](eg: observer problem mentioned above).

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1562#issuecomment-11903665.

@leepfrog

leepfrog commented Jan 4, 2013

Copy link
Copy Markdown

@twinturbo The fix listed above breaks tests, so something else will need to be done.

@mspisars

mspisars commented Feb 1, 2013

Copy link
Copy Markdown
Contributor

so... @igorT the API update/rewrite you mentioned in your comment above, is this something you are still planning on doing?

@ahawkins

Copy link
Copy Markdown
Author

@wycats @tomdale can we get a ruling on this? It's been sitting around for a while. There are some people who'd like to know where this is going to go.

@wycats

wycats commented Feb 28, 2013

Copy link
Copy Markdown
Member

We're going to close this in favor of making sortable and filterable composable. If there are bugs that make that hard today, let's fix them.

@wycats wycats closed this Feb 28, 2013
@wycats

wycats commented Feb 28, 2013

Copy link
Copy Markdown
Member

@twinturbo I hope you will work with @igorT on a PR that implements the composition idea.

@jherdman

Copy link
Copy Markdown
Contributor

@igorT I know you're super busy with ED these days, and it's been a while, but do you have your notes handy on how you wanted to handle ArrayProxy? I've been trying to hack away at a Filterable mixin lately, and bumped into the issues described here. I'm motivated to try and work on this issue.

@igorT

igorT commented Jun 17, 2014

Copy link
Copy Markdown
Member

All the comments here were before array/reduce computeds were created, so I
think those address a lot of issues.
On Jun 17, 2014 7:01 AM, "James Herdman" [email protected] wrote:

@igorT https://github.com/igorT I know you're super busy with ED these
days, and it's been a while, but do you have your notes handy on how you
wanted to handle ArrayProxy? I've been trying to hack away at a Filterable
mixin lately, and bumped into the issues described here. I'm motivated to
try and work on this issue.

—
Reply to this email directly or view it on GitHub
#1562 (comment).

ef4 pushed a commit that referenced this pull request Jan 6, 2026
[BUGFIX] properly surface deprecation message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.