event-manager.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { ReflectiveInjector } from "@angular/core";
  2. import { Events } from "ionic-angular";
  3. // import { EventSlots } from "./event-slot";
  4. /**
  5. *
  6. * ███████╗██╗ ██╗███████╗███╗ ██╗████████╗███████╗███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗██████╗
  7. * ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝██╔════╝████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝██╔══██╗
  8. * █████╗ ██║ ██║█████╗ ██╔██╗ ██║ ██║ ███████╗██╔████╔██║███████║██╔██╗ ██║███████║██║ ███╗█████╗ ██████╔╝
  9. * ██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ╚════██║██║╚██╔╝██║██╔══██║██║╚██╗██║██╔══██║██║ ██║██╔══╝ ██╔══██╗
  10. * ███████╗ ╚████╔╝ ███████╗██║ ╚████║ ██║ ███████║██║ ╚═╝ ██║██║ ██║██║ ╚████║██║ ██║╚██████╔╝███████╗██║ ██║
  11. * ╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
  12. *
  13. * Clase que contiene métodos que permiten compartir eventos en toda la aplicación
  14. */
  15. export abstract class EventsManager {
  16. private static EVENTS_INSTANCE;
  17. /**
  18. *
  19. */
  20. public static getManager(): Events {
  21. if (!EventsManager.EVENTS_INSTANCE) {
  22. EventsManager.EVENTS_INSTANCE = ReflectiveInjector.resolveAndCreate([Events]).get(Events);
  23. }
  24. return EventsManager.EVENTS_INSTANCE;
  25. }
  26. /**
  27. *
  28. * @param name
  29. * @param data
  30. */
  31. public static publish(name: string , data?: any): void {
  32. EventsManager.getManager().publish(name, data);
  33. }
  34. /**
  35. *
  36. * @param name
  37. */
  38. public static subscribe(name: string, handler: Function): any {
  39. EventsManager.getManager().subscribe(name, handler);
  40. }
  41. /**
  42. *
  43. * @param name
  44. */
  45. public static unsubscribe(name: string): void {
  46. EventsManager.getManager().unsubscribe(name);
  47. }
  48. }