项目原始demo,不改动
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

31 lines
915 B

  1. import { Subscription } from './Subscription';
  2. /**
  3. * We need this JSDoc comment for affecting ESDoc.
  4. * @ignore
  5. * @extends {Ignored}
  6. */
  7. export class SubjectSubscription extends Subscription {
  8. constructor(subject, subscriber) {
  9. super();
  10. this.subject = subject;
  11. this.subscriber = subscriber;
  12. this.closed = false;
  13. }
  14. unsubscribe() {
  15. if (this.closed) {
  16. return;
  17. }
  18. this.closed = true;
  19. const subject = this.subject;
  20. const observers = subject.observers;
  21. this.subject = null;
  22. if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
  23. return;
  24. }
  25. const subscriberIndex = observers.indexOf(this.subscriber);
  26. if (subscriberIndex !== -1) {
  27. observers.splice(subscriberIndex, 1);
  28. }
  29. }
  30. }
  31. //# sourceMappingURL=SubjectSubscription.js.map