mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import { Action } from '@ngrx/store';
|
|
|
|
import { type } from '../../shared/ngrx/type';
|
|
import { CacheableObject } from './object-cache.reducer';
|
|
import { Operation } from 'fast-json-patch';
|
|
import { RestRequest, RestRequestMethod } from '../data/request.models';
|
|
|
|
/**
|
|
* The list of ServerSyncBufferAction type definitions
|
|
*/
|
|
export const ServerSyncBufferActionTypes = {
|
|
ADD: type('dspace/core/cache/syncbuffer/ADD'),
|
|
COMMIT: type('dspace/core/cache/syncbuffer/COMMIT'),
|
|
EMPTY: type('dspace/core/cache/syncbuffer/EMPTY'),
|
|
};
|
|
|
|
/* tslint:disable:max-classes-per-file */
|
|
|
|
/**
|
|
* An ngrx action to add a new cached object to the server's sync buffer
|
|
*/
|
|
export class AddToSSBAction implements Action {
|
|
type = ServerSyncBufferActionTypes.ADD;
|
|
payload: {
|
|
href: string,
|
|
method: RestRequestMethod
|
|
};
|
|
|
|
/**
|
|
* Create a new AddToSSBAction
|
|
*
|
|
* @param href
|
|
* the unique href of the cached object entry that should be updated
|
|
*/
|
|
constructor(href: string, method: RestRequestMethod) {
|
|
this.payload = { href, method };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* An ngrx action to commit everything (for a certain method, when specified) in the ServerSyncBuffer to the server
|
|
*/
|
|
export class CommitSSBAction implements Action {
|
|
type = ServerSyncBufferActionTypes.COMMIT;
|
|
payload?: RestRequestMethod;
|
|
|
|
/**
|
|
* Create a new CommitSSBAction
|
|
*
|
|
* @param method
|
|
* an optional method for which the ServerSyncBuffer should send its entries to the server
|
|
*/
|
|
constructor(method?: RestRequestMethod) {
|
|
this.payload = method;
|
|
}
|
|
}
|
|
/**
|
|
* An ngrx action to remove everything (for a certain method, when specified) from the ServerSyncBuffer to the server
|
|
*/
|
|
export class EmptySSBAction implements Action {
|
|
type = ServerSyncBufferActionTypes.EMPTY;
|
|
payload?: RestRequestMethod;
|
|
|
|
/**
|
|
* Create a new EmptySSBAction
|
|
*
|
|
* @param method
|
|
* an optional method for which the ServerSyncBuffer should remove its entries
|
|
*/
|
|
constructor(method?: RestRequestMethod) {
|
|
this.payload = method;
|
|
}
|
|
}
|
|
|
|
/* tslint:enable:max-classes-per-file */
|
|
|
|
/**
|
|
* A type to encompass all ServerSyncBufferActions
|
|
*/
|
|
export type ServerSyncBufferAction
|
|
= AddToSSBAction
|
|
| CommitSSBAction
|
|
| EmptySSBAction
|