All files / src/lib puzzle.ts

100% Statements 14/14
75% Branches 3/4
100% Functions 4/4
100% Lines 14/14
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        10x     10x 10x 10x   10x     30x 20x   10x         2x 2x 2x           22x       3x 8x        
import {EVENT} from "./enums";
import {IEventListener} from "./types";
 
 
export class PuzzleJs {
  [module: string]: any;
 
  static PACKAGE_VERSION = '';
  static DEPENDENCIES = {};
  static LOGO = '';
 
  private static __LISTENERS: IEventListener = {};
 
  static subscribe(event: EVENT, cb: Function) {
    if (!PuzzleJs.__LISTENERS[event]) {
      PuzzleJs.__LISTENERS[event] = [cb];
    } else {
      PuzzleJs.__LISTENERS[event].push(cb);
    }
  }
 
  static emit(event: EVENT, ...data: any[]) {
    Eif (PuzzleJs.__LISTENERS[event]) {
      for (const listener of PuzzleJs.__LISTENERS[event]) {
        listener.apply(null, data);
      }
    }
  }
 
  static clearListeners() {
    PuzzleJs.__LISTENERS = {};
  }
 
  static inject(modules: { [name: string]: Function }) {
    for (const name in modules) {
      (PuzzleJs as any)[name] = modules[name];
    }
  }
}