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.1KB

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