Commit 1dc1d20d authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate AutosaveService to TypeScript

parent c7933df2
import type { SidebarStore } from '../store';
import { retryPromiseOperation } from '../util/retry'; import { retryPromiseOperation } from '../util/retry';
import type { AnnotationsService } from './annotations';
import type { ToastMessengerService } from './toast-messenger';
/** /**
* A service for automatically saving new highlights. * A service for automatically saving new highlights.
...@@ -6,20 +9,25 @@ import { retryPromiseOperation } from '../util/retry'; ...@@ -6,20 +9,25 @@ import { retryPromiseOperation } from '../util/retry';
* @inject * @inject
*/ */
export class AutosaveService { export class AutosaveService {
/** private _annotationsService: AnnotationsService;
* @param {import('./annotations').AnnotationsService} annotationsService private _toastMessenger: ToastMessengerService;
* @param {import('./toast-messenger').ToastMessengerService} toastMessenger private _store: SidebarStore;
* @param {import('../store').SidebarStore} store
*/ /** A set of annotation $tags that have save requests in-flight */
constructor(annotationsService, toastMessenger, store) { private _saving: Set<string>;
/** A set of annotation $tags that have failed to save after retries */
private _failed: Set<string>;
constructor(
annotationsService: AnnotationsService,
toastMessenger: ToastMessengerService,
store: SidebarStore
) {
this._annotationsService = annotationsService; this._annotationsService = annotationsService;
this._toastMessenger = toastMessenger; this._toastMessenger = toastMessenger;
this._store = store; this._store = store;
// A set of annotation $tags that have save requests in-flight
this._saving = new Set(); this._saving = new Set();
// A set of annotation $tags that have failed to save after retries
this._failed = new Set(); this._failed = new Set();
} }
...@@ -32,10 +40,9 @@ export class AutosaveService { ...@@ -32,10 +40,9 @@ export class AutosaveService {
* Determine whether we should try to send a save request for the highlight * Determine whether we should try to send a save request for the highlight
* indicated by `htag` * indicated by `htag`
* *
* @param {string} htag - The local unique identifier for the unsaved highlight * @param htag - The local unique identifier for the unsaved highlight
* @return {boolean}
*/ */
const shouldSaveHighlight = htag => { const shouldSaveHighlight = (htag: string): boolean => {
return !this._saving.has(htag) && !this._failed.has(htag); return !this._saving.has(htag) && !this._failed.has(htag);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment