A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.3 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * The Subject owns some important state and notifies observers when the state
  5. * changes.
  6. */
  7. // class ConcreteSubject implements Subject {
  8. // /**
  9. // * @type {number} For the sake of simplicity, the Subject's state, essential
  10. // * to all subscribers, is stored in this variable.
  11. // */
  12. // public state: number;
  13. // /**
  14. // * @type {Observer[]} List of subscribers. In real life, the list of
  15. // * subscribers can be stored more comprehensively (categorized by event
  16. // * type, etc.).
  17. // */
  18. // private observers: Observer[] = [];
  19. // /**
  20. // * The subscription management methods.
  21. // */
  22. // public attach(observer: Observer): void {
  23. // console.log('Subject: Attached an observer.');
  24. // this.observers.push(observer);
  25. // }
  26. // public detach(observer: Observer): void {
  27. // const observerIndex = this.observers.indexOf(observer);
  28. // this.observers.splice(observerIndex, 1);
  29. // console.log('Subject: Detached an observer.');
  30. // }
  31. // /**
  32. // * Trigger an update in each subscriber.
  33. // */
  34. // public notify(): void {
  35. // console.log('Subject: Notifying observers...');
  36. // for (const observer of this.observers) {
  37. // observer.update(this);
  38. // }
  39. // }
  40. // /**
  41. // * Usually, the subscription logic is only a fraction of what a Subject can
  42. // * really do. Subjects commonly hold some important business logic, that
  43. // * triggers a notification method whenever something important is about to
  44. // * happen (or after it).
  45. // */
  46. // public someBusinessLogic(): void {
  47. // console.log('\nSubject: I\'m doing something important.');
  48. // this.state = Math.floor(Math.random() * (10 + 1));
  49. // console.log(`Subject: My state has just changed to: ${this.state}`);
  50. // this.notify();
  51. // }
  52. // }
  53. // /**
  54. // * The client code.
  55. // */
  56. // const subject = new ConcreteSubject();
  57. // const observer1 = new ConcreteObserverA();
  58. // subject.attach(observer1);
  59. // const observer2 = new ConcreteObserverB();
  60. // subject.attach(observer2);
  61. // subject.someBusinessLogic();
  62. // subject.someBusinessLogic();
  63. // subject.detach(observer2);
  64. // subject.someBusinessLogic();