filterFilter doesn't work with Array like objects anymore #11782

Closed
superasn opened this Issue May 1, 2015 · 8 comments
@superasn
superasn commented May 1, 2015

filterFilter also doesn't work with Array like objects anymore, like it used to before.

Please take a look at this fiddle:

Works like it should with previous version of Angular (v1.2):
https://jsfiddle.net/superasn/gznzjgmb/

Breaks with newer versions of Angular (v1.3 and above):
https://jsfiddle.net/superasn/c15yvq6g/

@petebacondarwin
Member

@gkalpak can you take a look at this one?

@gonzaloruizdevilla gonzaloruizdevilla added a commit to gonzaloruizdevilla/angular.js that referenced this issue May 1, 2015
@gonzaloruizdevilla gonzaloruizdevilla fix(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
e09ed5d
@gkalpak
Member
gkalpak commented May 1, 2015

Will do.

@gonzaloruizdevilla gonzaloruizdevilla added a commit to gonzaloruizdevilla/angular.js that referenced this issue May 1, 2015
@gonzaloruizdevilla gonzaloruizdevilla fix(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
419f560
@gkalpak
Member
gkalpak commented May 2, 2015

A little background:

  • This was/is not working on 1.2.x. In fact, "array-like" objects have not been supported since v1.1.3.
  • In this context, "array-like" objects are objects prototypally inheriting from Array (so not what Angular internally refers to as "array-like" (i.e. objects for which isArrayLike() returns true)).
  • Pre v1.1.3, filterFilter was checking whether array instanceof Array (which included "subclasses" of Array). Then is switched to Object.prototype.toString.call(array) === '[object Array]' and later to Array.isArray(array).

That said, I don't see why we couldn't support array-like objects (in the internal Angular sense). It seems to be a trivial change.

@gonzaloruizdevilla has already submitted a PR (#11787) we can work on, so let's move the discussion there.

@gkalpak gkalpak self-assigned this May 2, 2015
@petebacondarwin
Member

One can ducktype an array for one's own purposes without it being a proper subclass and still like Angular to treat it like a collection in some cases.

@caitp
Contributor
caitp commented May 2, 2015

https://jsfiddle.net/0L11e3xf/ here's a proper version of the 1.3 repro posted above which works correctly, by subclassing the array "properly" --- but yes, filterFilter should replace isArray() with isArrayLike(), I guess. It would be a bonus if the isArrayLike() test didn't use the hasProperty() check :|

@gkalpak
Member
gkalpak commented May 2, 2015

@caitp, still not sure what you suggest :)

This doesn't work as is (because of the isArray(array) check and array.filter).
I suggested replacing isArray with isArrayLike and array.filter(...) with isArray(array) ? array.filter(...) : Array.prototype.filter.call(array, ...).

Are you saying something different ?

Regarding the length > 0 && (length - 1) in obj check in isArrayLike, I agree it is useless, but doesn't hurt either (other than slowing it down). I would be fine removing it.

@caitp
Contributor
caitp commented May 2, 2015

but yes, filterFilter should replace isArray() with isArrayLike(), I guess.

I had to re-word that whole slew of things to sound less negative, that's all

@gonzaloruizdevilla
Contributor

@gkalpak I don't think the typeof length === 'number' && length > 0 && (length - 1) in obj part is useless.
Actually, my PR #1938 with the first isArrayLike implementation was meant to distinguish between arrayLike objects and other objects with a numeric length property.

It's funny to see how today's implementation is so similar to the one I PR those days. @IgorMinar had to make a difficult implementation due to IE8 support in those versions (ec54712)

@gonzaloruizdevilla gonzaloruizdevilla added a commit to gonzaloruizdevilla/angular.js that referenced this issue May 16, 2015
@gonzaloruizdevilla gonzaloruizdevilla fix(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
7115bd1
@gonzaloruizdevilla gonzaloruizdevilla added a commit to gonzaloruizdevilla/angular.js that referenced this issue May 16, 2015
@gonzaloruizdevilla gonzaloruizdevilla fix(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
f4cdcf0
@gonzaloruizdevilla gonzaloruizdevilla added a commit to gonzaloruizdevilla/angular.js that referenced this issue May 19, 2015
@gonzaloruizdevilla gonzaloruizdevilla feat(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
42b6453
@gkalpak gkalpak added a commit that closed this issue May 19, 2015
@gonzaloruizdevilla @gkalpak gonzaloruizdevilla + gkalpak feat(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
Closes #11787
1b0d0fd
@gkalpak gkalpak closed this in 1b0d0fd May 19, 2015
@netman92 netman92 added a commit to netman92/angular.js that referenced this issue Aug 8, 2015
@gonzaloruizdevilla @netman92 gonzaloruizdevilla + netman92 feat(filterFilter): allow array like objects to be filtered
Throw error if filter is not used with an array like object.

Closes #11782
Closes #11787
c3baa00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment