Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

Notification.js 2.3KB

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