All files / src SSVGEngine.js

94.44% Statements 17/18
50% Branches 1/2
100% Functions 5/5
94.11% Lines 16/17

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        1x                 21x 21x   21x   21x   21x 21x 21x         19x 19x           169x 169x           1x 1x           3x     3x      
// @ts-check
 
import { select } from 'd3-selection';
import d from 'debug';
const debug = d('ssvg:engine');
 
import SSVGState from './SSVGState';
 
export default class SSVGEngine {
  /**
   * @param {Element} svg
   */
  constructor(svg /*: Element */) {
    debug('loading ssvg engine');
    this.svg = svg;
    /** @type {ssvg.StateSelection} */
    this.selection = /** @type {any} */ (select(svg));
    /** @type {SSVGState[]} */
    this.states = [];
 
    const states = svg.getElementsByTagName('state');
    for (let i = 0; i < states.length; ++i) {
      this.states.push(new SSVGState(this, states[i]));
    }
  }
 
  disconnect() {
    for (const s of this.states) {
      s.disconnect();
    }
  }
 
  /** @param {ssvg.$State} state */
  updateState(state) {
    for (const s of this.states) {
      s.updateState(state);
    }
  }
 
  /** @param {ssvg.$State} state */
  setState(state) {
    for (const s of this.states) {
      s.setState(state);
    }
  }
 
  /** @return {ssvg.$State} */
  getState() {
    Iif (this.states.length === 0) {
      return {};
    }
    return this.states[0].getState();
  }
}