Skip to content

Commit

Permalink
Fix/localfilter 56 (#62)
Browse files Browse the repository at this point in the history
* Now, if you are running demo:start and you touch src code, demo app is recompiled and reloaded

* README updated with a simple gif

* supress WARNING in Circular dependency detected

* localfilter fixed. 1.0.0-rc.12 Closes #56.
  • Loading branch information
pablorsk authored May 4, 2018
1 parent 4dfde2a commit c69b504
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class AuthorsComponent {
Filter resources with `attribute: value` values. Filters are used as 'exact match' (only resources with attribute value same as value are returned). `value` can also be an array, then only objects with same `attribute` value as one of `values` array elements are returned.

```javascript
let authors = authorsService.all(
let authors$ = authorsService.all(
{
localfilter: { name: 'xx' }, // request all data and next filter locally
remotefilter: { country: 'Argentina' } // request data with filter url parameter
Expand All @@ -166,7 +166,7 @@ let authors = authorsService.all(
From this point, you only see important code for this library. For a full example, clone and see demo directory.

```javascript
let author = authorsService.get('some_author_id');
let author$ = authorsService.get('some_author_id');
```

#### More options? Include resources when you fetch data (or save!)
Expand Down
6 changes: 6 additions & 0 deletions demo/app/authors/components/authors.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export class AuthorsComponent {
) {
authorsService.all(
// { include: ['books', 'photos'] }
// {
// localfilter: {
// name: 'y', // authors with a `y` character on name
// date_of_birth: /^2016\-.*/ // we can use regular expresions too :)
// }
// }
)
.subscribe(
authors => {
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-jsonapi",
"version": "1.0.0-rc.11",
"version": "1.0.0-rc.12",
"description": "JSON API library for Angular",
"module": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js",
"es2015": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.js",
Expand Down
4 changes: 2 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export class Service<R extends Resource = Resource> extends ParentResourceServic
fc_success,
fc_error,
tempororay_collection: ICollection<R>,
cached_collection: ICollection,
cached_collection: ICollection<R>,
subject: BehaviorSubject<ICollection<R>>
) {
// SERVER REQUEST
Expand Down Expand Up @@ -479,7 +479,7 @@ export class Service<R extends Resource = Resource> extends ParentResourceServic
}
}

subject.next(tempororay_collection);
subject.next(cached_collection);
subject.complete();
this.runFc(fc_success, success);
})
Expand Down
5 changes: 2 additions & 3 deletions src/services/localfilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export class LocalFilter {
);
} else if (typeof resource.attributes[attribute] === 'string') {
// just a string
return (
resource.attributes[attribute] === localfilter[attribute]
);
return resource.attributes[attribute].includes(localfilter[attribute]);
}
}

Expand All @@ -41,5 +39,6 @@ export class LocalFilter {
}
});
}
console.log('y quedó así', dest_collection);
}
}

0 comments on commit c69b504

Please sign in to comment.