mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 03:53:02 +00:00
implementation of server synchronization
This commit is contained in:
83
src/app/core/cache/server-sync-buffer.actions.ts
vendored
Normal file
83
src/app/core/cache/server-sync-buffer.actions.ts
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
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
|
Reference in New Issue
Block a user