mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
Switched to storing requests based on UUID, generalized UUIDIndexReducer to work with any type of index
This commit is contained in:
61
src/app/core/index/index.effects.ts
Normal file
61
src/app/core/index/index.effects.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Effect, Actions } from '@ngrx/effects';
|
||||
|
||||
import {
|
||||
ObjectCacheActionTypes, AddToObjectCacheAction,
|
||||
RemoveFromObjectCacheAction
|
||||
} from '../cache/object-cache.actions';
|
||||
import { RequestActionTypes, RequestConfigureAction } from '../data/request.actions';
|
||||
import { RestRequestMethod } from '../data/request.models';
|
||||
import { AddToIndexAction, RemoveFromIndexByValueAction } from './index.actions';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import { IndexName } from './index.reducer';
|
||||
|
||||
@Injectable()
|
||||
export class UUIDIndexEffects {
|
||||
|
||||
@Effect() addObject$ = this.actions$
|
||||
.ofType(ObjectCacheActionTypes.ADD)
|
||||
.filter((action: AddToObjectCacheAction) => hasValue(action.payload.objectToCache.uuid))
|
||||
.map((action: AddToObjectCacheAction) => {
|
||||
return new AddToIndexAction(
|
||||
IndexName.OBJECT,
|
||||
action.payload.objectToCache.uuid,
|
||||
action.payload.objectToCache.self
|
||||
);
|
||||
});
|
||||
|
||||
@Effect() removeObject$ = this.actions$
|
||||
.ofType(ObjectCacheActionTypes.REMOVE)
|
||||
.map((action: RemoveFromObjectCacheAction) => {
|
||||
return new RemoveFromIndexByValueAction(
|
||||
IndexName.OBJECT,
|
||||
action.payload
|
||||
);
|
||||
});
|
||||
|
||||
@Effect() addRequest$ = this.actions$
|
||||
.ofType(RequestActionTypes.CONFIGURE)
|
||||
.filter((action: RequestConfigureAction) => action.payload.method === RestRequestMethod.Get)
|
||||
.map((action: RequestConfigureAction) => {
|
||||
return new AddToIndexAction(
|
||||
IndexName.REQUEST,
|
||||
action.payload.href,
|
||||
action.payload.uuid
|
||||
);
|
||||
});
|
||||
|
||||
// @Effect() removeRequest$ = this.actions$
|
||||
// .ofType(ObjectCacheActionTypes.REMOVE)
|
||||
// .map((action: RemoveFromObjectCacheAction) => {
|
||||
// return new RemoveFromIndexByValueAction(
|
||||
// IndexName.OBJECT,
|
||||
// action.payload
|
||||
// );
|
||||
// });
|
||||
|
||||
constructor(private actions$: Actions) {
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user