wishthis/node_modules/rxjs/_esm2015/internal/operators/multicast.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-05-29 09:24:36 +00:00
import { connectableObservableDescriptor } from '../observable/ConnectableObservable';
export function multicast(subjectOrSubjectFactory, selector) {
return function multicastOperatorFunction(source) {
let subjectFactory;
if (typeof subjectOrSubjectFactory === 'function') {
subjectFactory = subjectOrSubjectFactory;
}
else {
subjectFactory = function subjectFactory() {
return subjectOrSubjectFactory;
};
}
if (typeof selector === 'function') {
return source.lift(new MulticastOperator(subjectFactory, selector));
}
const connectable = Object.create(source, connectableObservableDescriptor);
connectable.source = source;
connectable.subjectFactory = subjectFactory;
return connectable;
};
}
export class MulticastOperator {
constructor(subjectFactory, selector) {
this.subjectFactory = subjectFactory;
this.selector = selector;
}
call(subscriber, source) {
const { selector } = this;
const subject = this.subjectFactory();
const subscription = selector(subject).subscribe(subscriber);
subscription.add(source.subscribe(subject));
return subscription;
}
}
//# sourceMappingURL=multicast.js.map