All files / src/impl Storage.impl.ts

90.9% Statements 10/11
100% Branches 0/0
75% Functions 3/4
90.9% Lines 10/11

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 28 29 30 31 32 33 34 35 36 37 38 39            25x       25x     1170x 1170x 1170x 1170x               1169x 1169x       2162x             1170x    
import { AutoClose, AutoCloseOne } from "@jonloucks/contracts-ts/api/AutoClose";
import { BindStrategy } from "@jonloucks/contracts-ts/api/BindStrategy";
import { Contract } from "@jonloucks/contracts-ts/api/Contract";
import { Contracts } from "@jonloucks/contracts-ts/api/Contracts";
import { Promisor } from "@jonloucks/contracts-ts/api/Promisor";
 
import { create as createAutoCloseOne } from "./AutoCloseOne.impl";
 
// ---- Implementation details below ----
 
export class StorageImpl<T> implements AutoClose {
  
  constructor(contracts: Contracts, contract: Contract<T>, promisor: Promisor<T | null>, bindStrategy: BindStrategy) {
    this.contracts = contracts;
    this.contract = contract;
    this.promisor = promisor;
    this.bindStrategy = bindStrategy;
  }
 
  [Symbol.dispose](): void {
    this.close();
  }
 
  bind(): void {
    this.close();
    this.closeBinding.set(this.contracts.bind(this.contract, this.promisor, this.bindStrategy));
  }
 
  close(): void {
    this.closeBinding.close();
  }
 
  private readonly contract: Contract<T>;
  private readonly promisor: Promisor<T | null>;
  private readonly bindStrategy: BindStrategy;
  private readonly contracts: Contracts;
  private readonly closeBinding: AutoCloseOne = createAutoCloseOne();
}