Skip to content

Commit

Permalink
Add select resources pipe to module (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawamoto authored and remmeier committed May 11, 2018
1 parent 530f6b9 commit c006475
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/pipes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Pipes', () => {
);

it('should return Observable of StoreResource', () => {
const ids = [{id: '2', type: 'Article'}, {id: '1', type: 'Article'}]
const ids = [{ id: '2', type: 'Article' }, { id: '1', type: 'Article' }];
pipe.transform(ids).subscribe(it => {
expect(_.get(it[0], 'attributes.title')).toBe('Article 2');
expect(_.get(it[1], 'attributes.title')).toBe('Article 1');
Expand Down
15 changes: 13 additions & 2 deletions spec/selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ describe('NgrxJsonApiSelectors', () => {
fakeAsync(() => {
let res;
let sub = store
.let(selectStoreResources([{ type: 'Article', id: '1' }, { type: 'Article', id: '2'}]))
.let(
selectStoreResources([
{ type: 'Article', id: '1' },
{ type: 'Article', id: '2' },
])
)
.subscribe(d => (res = d));
tick();
expect(res[0].attributes.title).toEqual('Article 1');
Expand All @@ -233,7 +238,13 @@ describe('NgrxJsonApiSelectors', () => {
fakeAsync(() => {
let res;
let sub = store
.let(selectStoreResources([{ type: 'Article', id: '100' }, { type: 'Article', id: '1'}, {type: 'Unknown', id: '1'}]))
.let(
selectStoreResources([
{ type: 'Article', id: '100' },
{ type: 'Article', id: '1' },
{ type: 'Unknown', id: '1' },
])
)
.subscribe(d => (res = d));
tick();
expect(res[0]).not.toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion spec/services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('NgrxJsonApiService', () => {
{
type: 'Article',
id: '2',
}
},
]);
storeResources.subscribe(it => {
expect(it[0].type).toEqual('Article');
Expand Down
3 changes: 3 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DenormaliseStoreResourcePipe,
GetDenormalisedValuePipe,
SelectStoreResourcePipe,
SelectStoreResourcesPipe,
} from './pipes';

import { NgrxJsonApiConfig } from './interfaces';
Expand Down Expand Up @@ -65,6 +66,7 @@ export function configure(config: NgrxJsonApiConfig): Array<any> {
DenormaliseStoreResourcePipe,
GetDenormalisedValuePipe,
SelectStoreResourcePipe,
SelectStoreResourcesPipe,
],
imports: [
EffectsModule.forFeature([NgrxJsonApiEffects]),
Expand All @@ -74,6 +76,7 @@ export function configure(config: NgrxJsonApiConfig): Array<any> {
DenormaliseStoreResourcePipe,
GetDenormalisedValuePipe,
SelectStoreResourcePipe,
SelectStoreResourcesPipe,
],
})
export class NgrxJsonApiModule {
Expand Down
3 changes: 2 additions & 1 deletion src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export function selectStoreResources(identifiers: ResourceIdentifier[]) {
}
return data[identifier.type][identifier.id] as StoreResource;
});
}));
})
);
};
}

Expand Down

0 comments on commit c006475

Please sign in to comment.