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.

41 lines
1.4 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var UserModel = /** @class */ (function () {
  4. function UserModel() {
  5. /**
  6. * @type {Observer[]} List of subscribers. In real life, the list of
  7. * subscribers can be stored more comprehensively (categorized by event
  8. * type, etc.).
  9. */
  10. this.observers = [];
  11. this.state = 0;
  12. }
  13. /**
  14. * The subscription management methods.
  15. */
  16. UserModel.prototype.attach = function (observer) {
  17. console.log('Subject: Attached an observer.');
  18. this.observers.push(observer);
  19. };
  20. UserModel.prototype.detach = function (observer) {
  21. var observerIndex = this.observers.indexOf(observer);
  22. this.observers.splice(observerIndex, 1);
  23. console.log('Subject: Detached an observer.');
  24. };
  25. /**
  26. * Trigger an update in each subscriber.
  27. */
  28. UserModel.prototype.notify = function () {
  29. console.log('Subject: Notifying observers...');
  30. for (var _i = 0, _a = this.observers; _i < _a.length; _i++) {
  31. var observer = _a[_i];
  32. observer.update(this.state);
  33. }
  34. };
  35. UserModel.prototype.someBusinessMethod = function () {
  36. console.log("Subject: My state has just changed to: " + this.state);
  37. this.notify();
  38. };
  39. return UserModel;
  40. }());
  41. exports.UserModel = UserModel;