All files / src/persistence/inMemoryStores InMemoryDocumentStore.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 3/3
100% Lines 10/10

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  41x 41x   41x 1309x     1342x 11x       1243x 1242x 1242x   1x      
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;
  }
}