Fixed an issue where, if you called findAll or findById multiple times in a row, all network requests were cancelled except for the last one.

This commit is contained in:
Art Lowel
2017-02-24 13:11:14 +01:00
parent 7fb8360f10
commit b0f25c4dae

View File

@@ -30,7 +30,7 @@ export abstract class DataEffects<T extends CacheableObject> {
protected findAll = this.actions$ protected findAll = this.actions$
.ofType(RequestCacheActionTypes.FIND_ALL_REQUEST) .ofType(RequestCacheActionTypes.FIND_ALL_REQUEST)
.filter((action: FindAllRequestCacheAction) => action.payload.service === this.dataService.name) .filter((action: FindAllRequestCacheAction) => action.payload.service === this.dataService.name)
.switchMap((action: FindAllRequestCacheAction) => { .flatMap((action: FindAllRequestCacheAction) => {
//TODO scope, pagination, sorting -> when we know how that works in rest //TODO scope, pagination, sorting -> when we know how that works in rest
return this.restApi.get(this.getFindAllEndpoint(action)) return this.restApi.get(this.getFindAllEndpoint(action))
.map((data: DSpaceRESTV2Response) => this.getSerializer().deserializeArray(data)) .map((data: DSpaceRESTV2Response) => this.getSerializer().deserializeArray(data))
@@ -47,7 +47,7 @@ export abstract class DataEffects<T extends CacheableObject> {
protected findById = this.actions$ protected findById = this.actions$
.ofType(RequestCacheActionTypes.FIND_BY_ID_REQUEST) .ofType(RequestCacheActionTypes.FIND_BY_ID_REQUEST)
.filter((action: FindAllRequestCacheAction) => action.payload.service === this.dataService.name) .filter((action: FindAllRequestCacheAction) => action.payload.service === this.dataService.name)
.switchMap((action: FindByIDRequestCacheAction) => { .flatMap((action: FindByIDRequestCacheAction) => {
return this.restApi.get(this.getFindByIdEndpoint(action)) return this.restApi.get(this.getFindByIdEndpoint(action))
.map((data: DSpaceRESTV2Response) => this.getSerializer().deserialize(data)) .map((data: DSpaceRESTV2Response) => this.getSerializer().deserialize(data))
.do((t: T) => { .do((t: T) => {