Ohm-Management - Projektarbeit B-ME
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.

Notification.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var empty_1 = require("./observable/empty");
  4. var of_1 = require("./observable/of");
  5. var throwError_1 = require("./observable/throwError");
  6. var Notification = (function () {
  7. function Notification(kind, value, error) {
  8. this.kind = kind;
  9. this.value = value;
  10. this.error = error;
  11. this.hasValue = kind === 'N';
  12. }
  13. Notification.prototype.observe = function (observer) {
  14. switch (this.kind) {
  15. case 'N':
  16. return observer.next && observer.next(this.value);
  17. case 'E':
  18. return observer.error && observer.error(this.error);
  19. case 'C':
  20. return observer.complete && observer.complete();
  21. }
  22. };
  23. Notification.prototype.do = function (next, error, complete) {
  24. var kind = this.kind;
  25. switch (kind) {
  26. case 'N':
  27. return next && next(this.value);
  28. case 'E':
  29. return error && error(this.error);
  30. case 'C':
  31. return complete && complete();
  32. }
  33. };
  34. Notification.prototype.accept = function (nextOrObserver, error, complete) {
  35. if (nextOrObserver && typeof nextOrObserver.next === 'function') {
  36. return this.observe(nextOrObserver);
  37. }
  38. else {
  39. return this.do(nextOrObserver, error, complete);
  40. }
  41. };
  42. Notification.prototype.toObservable = function () {
  43. var kind = this.kind;
  44. switch (kind) {
  45. case 'N':
  46. return of_1.of(this.value);
  47. case 'E':
  48. return throwError_1.throwError(this.error);
  49. case 'C':
  50. return empty_1.empty();
  51. }
  52. throw new Error('unexpected notification kind value');
  53. };
  54. Notification.createNext = function (value) {
  55. if (typeof value !== 'undefined') {
  56. return new Notification('N', value);
  57. }
  58. return Notification.undefinedValueNotification;
  59. };
  60. Notification.createError = function (err) {
  61. return new Notification('E', undefined, err);
  62. };
  63. Notification.createComplete = function () {
  64. return Notification.completeNotification;
  65. };
  66. Notification.completeNotification = new Notification('C');
  67. Notification.undefinedValueNotification = new Notification('N', undefined);
  68. return Notification;
  69. }());
  70. exports.Notification = Notification;
  71. //# sourceMappingURL=Notification.js.map