share.js 1.0KB

12345678910111213141516171819202122232425
  1. /** PURE_IMPORTS_START ._multicast,._refCount,.._Subject PURE_IMPORTS_END */
  2. import { multicast } from './multicast';
  3. import { refCount } from './refCount';
  4. import { Subject } from '../Subject';
  5. function shareSubjectFactory() {
  6. return new Subject();
  7. }
  8. /**
  9. * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one
  10. * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will
  11. * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`.
  12. * This is an alias for .multicast(() => new Subject()).refCount().
  13. *
  14. * <img src="./img/share.png" width="100%">
  15. *
  16. * @return {Observable<T>} An Observable that upon connection causes the source Observable to emit items to its Observers.
  17. * @method share
  18. * @owner Observable
  19. */
  20. export function share() {
  21. return function (source) { return refCount()(multicast(shareSubjectFactory)(source)); };
  22. }
  23. ;
  24. //# sourceMappingURL=share.js.map