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

multicast.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { connectableObservableDescriptor } from '../observable/ConnectableObservable';
  2. export function multicast(subjectOrSubjectFactory, selector) {
  3. return function multicastOperatorFunction(source) {
  4. let subjectFactory;
  5. if (typeof subjectOrSubjectFactory === 'function') {
  6. subjectFactory = subjectOrSubjectFactory;
  7. }
  8. else {
  9. subjectFactory = function subjectFactory() {
  10. return subjectOrSubjectFactory;
  11. };
  12. }
  13. if (typeof selector === 'function') {
  14. return source.lift(new MulticastOperator(subjectFactory, selector));
  15. }
  16. const connectable = Object.create(source, connectableObservableDescriptor);
  17. connectable.source = source;
  18. connectable.subjectFactory = subjectFactory;
  19. return connectable;
  20. };
  21. }
  22. export class MulticastOperator {
  23. constructor(subjectFactory, selector) {
  24. this.subjectFactory = subjectFactory;
  25. this.selector = selector;
  26. }
  27. call(subscriber, source) {
  28. const { selector } = this;
  29. const subject = this.subjectFactory();
  30. const subscription = selector(subject).subscribe(subscriber);
  31. subscription.add(source.subscribe(subject));
  32. return subscription;
  33. }
  34. }
  35. //# sourceMappingURL=multicast.js.map