Front end of the Slack clone application.

AsyncSubject.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Subject } from './Subject';
  2. import { Subscription } from './Subscription';
  3. /**
  4. * @class AsyncSubject<T>
  5. */
  6. export class AsyncSubject extends Subject {
  7. constructor() {
  8. super(...arguments);
  9. this.value = null;
  10. this.hasNext = false;
  11. this.hasCompleted = false;
  12. }
  13. /** @deprecated internal use only */ _subscribe(subscriber) {
  14. if (this.hasError) {
  15. subscriber.error(this.thrownError);
  16. return Subscription.EMPTY;
  17. }
  18. else if (this.hasCompleted && this.hasNext) {
  19. subscriber.next(this.value);
  20. subscriber.complete();
  21. return Subscription.EMPTY;
  22. }
  23. return super._subscribe(subscriber);
  24. }
  25. next(value) {
  26. if (!this.hasCompleted) {
  27. this.value = value;
  28. this.hasNext = true;
  29. }
  30. }
  31. error(error) {
  32. if (!this.hasCompleted) {
  33. super.error(error);
  34. }
  35. }
  36. complete() {
  37. this.hasCompleted = true;
  38. if (this.hasNext) {
  39. super.next(this.value);
  40. }
  41. super.complete();
  42. }
  43. }
  44. //# sourceMappingURL=AsyncSubject.js.map