All files / src/store StoreMonitorElement.ts

96.1% Statements 74/77
85.71% Branches 6/7
75% Functions 6/8
96.1% Lines 74/77

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78126x   126x 126x 126x 126x 126x 126x 126x 126x 126x 123x     126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 155x 155x 126x 6x 6x 6x 6x 6x 6x 6x 126x 19x 19x 19x 19x 19x 119x 119x 119x 119x 126x 126x 126x 126x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x 126x  
import { html, TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
import { CustomEventType } from '../interfaces';
import { RapidElement } from '../RapidElement';
import { Store } from './Store';
 
/**
 * StoreMonitorElement notifies when the store is updated and with what url
 */
export class StoreMonitorElement extends RapidElement {
  @property({ type: String })
  url: string;

  @property({ type: Boolean })
  showLoading = false;
 
  @property({ type: Boolean })
  dirty = false;
 
  @property({ type: String })
  dirtyMessage: string;
 
  store: Store;
 
  markDirty() {
    this.dirty = true;
    this.store.markDirty(this);
    this.fireCustomEvent(CustomEventType.DetailsChanged, {
      dirty: true
    });
  }
 
  markClean() {
    this.dirty = false;
    this.store.markClean(this);
    this.fireCustomEvent(CustomEventType.DetailsChanged, {
      dirty: false
    });
  }
 
  private handleStoreUpdated(event: CustomEvent) {
    this.storeUpdated(event);
  }
 
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
  protected storeUpdated(event: CustomEvent) {}
 
  connectedCallback(): void {
    super.connectedCallback();
    this.store = document.querySelector('temba-store') as Store;
    this.handleStoreUpdated = this.handleStoreUpdated.bind(this);
    if (this.store) {
      this.store.addEventListener(
        CustomEventType.StoreUpdated,
        this.handleStoreUpdated
      );
    }
  }
 
  disconnectedCallback(): void {
    super.disconnectedCallback();
    if (this.store) {
      this.store.removeEventListener(
        CustomEventType.StoreUpdated,
        this.handleStoreUpdated
      );
 
      this.store.markClean(this);
    }
  }
 
  public render(): TemplateResult {
    if (!this.store.ready && this.showLoading) {
      return html`<temba-loading></temba-loading>`;
    }
  }
}