multicast.js 1.5 KB

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