1
0

Observable.Binding.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using UniRx.Operators;
  3. namespace UniRx
  4. {
  5. public static partial class Observable
  6. {
  7. public static IConnectableObservable<T> Multicast<T>(this IObservable<T> source, ISubject<T> subject)
  8. {
  9. return new ConnectableObservable<T>(source, subject);
  10. }
  11. public static IConnectableObservable<T> Publish<T>(this IObservable<T> source)
  12. {
  13. return source.Multicast(new Subject<T>());
  14. }
  15. public static IConnectableObservable<T> Publish<T>(this IObservable<T> source, T initialValue)
  16. {
  17. return source.Multicast(new BehaviorSubject<T>(initialValue));
  18. }
  19. public static IConnectableObservable<T> PublishLast<T>(this IObservable<T> source)
  20. {
  21. return source.Multicast(new AsyncSubject<T>());
  22. }
  23. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source)
  24. {
  25. return source.Multicast(new ReplaySubject<T>());
  26. }
  27. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source, IScheduler scheduler)
  28. {
  29. return source.Multicast(new ReplaySubject<T>(scheduler));
  30. }
  31. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source, int bufferSize)
  32. {
  33. return source.Multicast(new ReplaySubject<T>(bufferSize));
  34. }
  35. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source, int bufferSize, IScheduler scheduler)
  36. {
  37. return source.Multicast(new ReplaySubject<T>(bufferSize, scheduler));
  38. }
  39. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source, TimeSpan window)
  40. {
  41. return source.Multicast(new ReplaySubject<T>(window));
  42. }
  43. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source, TimeSpan window, IScheduler scheduler)
  44. {
  45. return source.Multicast(new ReplaySubject<T>(window, scheduler));
  46. }
  47. public static IConnectableObservable<T> Replay<T>(this IObservable<T> source, int bufferSize, TimeSpan window, IScheduler scheduler)
  48. {
  49. return source.Multicast(new ReplaySubject<T>(bufferSize, window, scheduler));
  50. }
  51. public static IObservable<T> RefCount<T>(this IConnectableObservable<T> source)
  52. {
  53. return new RefCountObservable<T>(source);
  54. }
  55. /// <summary>
  56. /// same as Publish().RefCount()
  57. /// </summary>
  58. public static IObservable<T> Share<T>(this IObservable<T> source)
  59. {
  60. return source.Publish().RefCount();
  61. }
  62. }
  63. }