All files / src/persistence/inMemoryStores InMemoryDocumentStore.ts

93.33% Statements 14/15
80% Branches 4/5
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  43x 43x   43x 1448x     1727x 137x       1279x 1278x 1278x   1x       2x 2x 2x      
import { DocumentStore } from '../types';
import { EMPTY, Observable, of } from 'rxjs';
import { InMemoryStore } from './InMemoryStore';
 
export class InMemoryDocumentStore<T> extends InMemoryStore implements DocumentStore<T> {
  #doc: T | null = null;
 
  get(): Observable<T> {
    if (!this.#doc || this.destroyed) return EMPTY;
    return of(this.#doc);
  }
 
  set(doc: T): Observable<void> {
    if (!this.destroyed) {
      this.#doc = doc;
      return of(void 0);
    }
    return EMPTY;
  }
 
  delete(): Observable<void> {
    Iif (this.destroyed) return EMPTY;
    this.#doc = null;
    return of(void 0);
  }
}