Skip to content

Commit

Permalink
Merge branch 'master' of github.com:VadimDez/ngx-filter-pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimDez committed Dec 18, 2017
2 parents ad1c1ad + d8bee19 commit 8806e33
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ testem.log
#System Files
.DS_Store
Thumbs.db

yarn.lock
30 changes: 30 additions & 0 deletions examples/ng-cli/src/app/shared/ngx-filter.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ describe('Pipe: FilterPipe', () => {
expect(pipe.transform(objects, { name: 'Qwe123' })).toEqual([]);
});

it('should get value from getter defined in class ancestor', () => {
class User {
firstName: string;
lastName: string;

constructor(first: string, last: string) {
this.firstName = first;
this.lastName = last;
}

get name() {
return `${ this.firstName } ${ this.lastName }`;
}
}

class UserEx extends User {

}

const userA = new UserEx('Abc', '123');
const objects = [
userA,
new UserEx('Qwe', '123')
];

expect(pipe.transform(objects, { name: '123' })).toEqual(objects);
expect(pipe.transform(objects, { name: 'Abc 123' })).toEqual([userA]);
expect(pipe.transform(objects, { name: 'Qwe123' })).toEqual([]);
});

it('should filter by empty filter string', () => {
const objects = [
'test',
Expand Down
13 changes: 11 additions & 2 deletions examples/ng-cli/src/app/shared/ngx-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ export class FilterPipe {
continue;
}

if (!value.hasOwnProperty(key) && !Object.getOwnPropertyDescriptor(Object.getPrototypeOf(value), key)) {
let walker = value;
let found = false;
do {
if (walker.hasOwnProperty(key) || Object.getOwnPropertyDescriptor(walker, key)) {
found = true;
break;
}
} while (walker = Object.getPrototypeOf(walker));

if (!found) {
return false;
}

Expand Down Expand Up @@ -148,4 +157,4 @@ export class FilterPipe {

return array.filter(this.filterDefault(filter));
}
}
}

0 comments on commit 8806e33

Please sign in to comment.