示例#1
0
 public static IRxVal <B> map <A, B>(this IRxVal <A> src, Fn <A, B> mapper) =>
 new RxVal <B>(
     mapper(src.value),
     setValue => src.subscribeWithoutEmit(
         NoOpDisposableTracker.instance, a => setValue(mapper(a))
         )
     );
示例#2
0
 public StandardBannerAggregator(
     ImmutableList <IStandardBannerKnowsState> banners
     )
 {
     this.banners = banners;
     hasAd        = banners.Select(_ => _.hasAd).anyOf();
 }
示例#3
0
        public SingleItemLoader()
        {
            itemState = currentLoader.flatMap(opt => {
                discardPreviousRequest();
                foreach (var bindingLoader in opt)
                {
                    var(_request, assetFtr) = bindingLoader.loadASync();
                    request.value           = _request.some();
                    return(assetFtr.toRxVal().map(csOpt => csOpt.toRight(new IsLoading(true))));
                }

                return(RxVal.cached(F.left <IsLoading, A>(new IsLoading(false))));
            });

            itemState.subscribe(tracker, e => {
                if (e.isRight)
                {
                    discardPreviousRequest();
                }
            });

            currentLoader.zip(priority, request, (show, _priority, req) =>
                              F.t(show.isSome ? (_priority == LoadPriority.High ? PRIORITY_HIGH : PRIORITY_LOW) : PRIORITY_OFF, req)
                              ).subscribe(tracker, tpl => {
                var(_priority, req) = tpl;
                foreach (var r in req)
                {
                    r.priority = _priority;
                }
            });
        }
示例#4
0
 public static IRxVal <Tpl <A, A1, A2, A3, A4, A5> > zip <A, A1, A2, A3, A4, A5>(
     this IRxVal <A> ref1, IRxVal <A1> ref2, IRxVal <A2> ref3, IRxVal <A3> ref4, IRxVal <A4> ref5,
     IRxVal <A5> ref6
     ) => RxVal.a(
     () => F.t(ref1.value, ref2.value, ref3.value, ref4.value, ref5.value, ref6.value),
     ObservableOpImpls.zip(ref1, ref2, ref3, ref4, ref5, ref6)
     );
示例#5
0
 public IRxVal <Tpl <A, B, C, D> > zip <B, C, D>(
     IRxVal <B> ref2, IRxVal <C> ref3, IRxVal <D> ref4
     )
 {
     return(zipImpl(
                ref2, ref3, ref4, RxVal.builder(() => F.t(currentValue, ref2.value, ref3.value, ref4.value))
                ));
 }
示例#6
0
 public static IRxVal <Option <B> > optFlatMap <A, B>(
     this IRxVal <Option <A> > source, Fn <A, IRxVal <Option <B> > > extractor
     ) =>
 source.flatMap(aOpt =>
                aOpt.fold(
                    () => RxVal.cached(F.none <B>()),
                    extractor
                    )
                );
示例#7
0
 public IRxVal <Tpl <A, A1, A2, A3, A4, A5> > zip <A1, A2, A3, A4, A5>(
     IRxVal <A1> ref2, IRxVal <A2> ref3, IRxVal <A3> ref4, IRxVal <A4> ref5, IRxVal <A5> ref6
     )
 {
     return(zipImpl(
                ref2, ref3, ref4, ref5, ref6,
                RxVal.builder(() => F.t(currentValue, ref2.value, ref3.value, ref4.value, ref5.value, ref6.value))
                ));
 }
示例#8
0
 public static IRxVal <R> zip <A1, A2, R>(
     this IRxVal <A1> a1Src, IRxVal <A2> a2Src, Fn <A1, A2, R> zipper
     ) =>
 new RxVal <R>(
     zipper(a1Src.value, a2Src.value),
     setValue => {
     var tracker = NoOpDisposableTracker.instance;
     var a1Sub   = a1Src.subscribeWithoutEmit(tracker, a1 => setValue(zipper(a1, a2Src.value)));
     var a2Sub   = a2Src.subscribeWithoutEmit(tracker, a2 => setValue(zipper(a1Src.value, a2)));
     return(a1Sub.join(a2Sub));
 }
     );
示例#9
0
        public void ctor() => describe(() => {
            var mapperInvocations        = 0;
            var actionInvocations        = 0;
            var lastActionResult         = 0;
            IRxRef <Tpl <int, int> > src = null;
            IRxVal <int> rx = null;

            beforeEach += () => {
                mapperInvocations = 0;
                actionInvocations = 0;
                src = RxRef.a(F.t(10, 0));
                rx  = new RxVal <int>(
                    -11,
                    setValue => src.subscribeWithoutEmit(tracker, t => {
                    mapperInvocations++;
                    setValue(t._1 + t._2 + 1);
                })
                    );
                rx.subscribe(tracker, i => {
                    actionInvocations++;
                    lastActionResult = i;
                });
            };

            on["creation"] = () => {
                it["should create a subscription to source"] = () => src.subscribers.shouldEqual(1);
                it["should not invoke mapper"]                = () => mapperInvocations.shouldEqual(0);
                it["should have specified value"]             = () => rx.value.shouldEqual(-11);
                it["should invoke action"]                    = () => actionInvocations.shouldEqual(1);
                it["should invoke action with current value"] = () => lastActionResult.shouldEqual(-11);

                when["source changes"] = () => {
                    beforeEach += () => src.value = F.t(2, 3);

                    it["should invoke mapper"] = () => mapperInvocations.shouldEqual(1);
                    it["should update value"]  = () => rx.value.shouldEqual(6);
                    it["should invoke action"] = () => actionInvocations.shouldEqual(2);
                    it["should invoke action with recomputed value"] = () => lastActionResult.shouldEqual(6);

                    when["source changes, but transformation result is the same"] = () => {
                        beforeEach += () => src.value = F.t(3, 2);

                        it["should invoke mapper"]       = () => mapperInvocations.shouldEqual(2);
                        it["should keep the value same"] = () => rx.value.shouldEqual(6);
                        it["should not invoke action"]   = () => actionInvocations.shouldEqual(2);
                    };
                };
            };
        });
示例#10
0
        public static IRxVal <B> flatMap <A, B>(this IRxVal <A> src, Fn <A, IRxVal <B> > mapper)
        {
            var bRx = mapper(src.value);

            return(new RxVal <B>(
                       bRx.value,
                       setValue => {
                var tracker = NoOpDisposableTracker.instance;
                var subToBRx = bRx.subscribeWithoutEmit(tracker, b => setValue(b));

                var aSub = src.subscribeWithoutEmit(
                    tracker,
                    a => {
                    subToBRx.unsubscribe();
                    bRx = mapper(a);
                    setValue(bRx.value);
                    subToBRx = bRx.subscribeWithoutEmit(tracker, b => setValue(b));
                }
                    );
                return aSub.andThen(() => subToBRx.unsubscribe());
            }
                       ));
        }
示例#11
0
 public static IRxVal <B> map <A, B>(this IRxVal <A> rx, Fn <A, B> mapper) =>
 RxVal.a(() => mapper(rx.value), ObservableOpImpls.map(rx, mapper));
示例#12
0
 public IRxVal <Tpl <A, B> > zip <B>(IRxVal <B> ref2)
 {
     return(zipImpl(ref2, RxVal.builder(() => F.t(currentValue, ref2.value))));
 }
示例#13
0
 public static IRxVal <Tpl <A, B, C> > zip <A, B, C>(
     this IRxVal <A> rx, IRxVal <B> rx2, IRxVal <C> rx3
     ) => RxVal.a(
     () => F.t(rx.value, rx2.value, rx3.value),
     ObservableOpImpls.zip(rx, rx2, rx3)
     );
示例#14
0
 public static IRxVal <Tpl <A, B, C, D, E> > zip <A, B, C, D, E>(
     this IRxVal <A> ref1, IRxVal <B> ref2, IRxVal <C> ref3, IRxVal <D> ref4, IRxVal <E> ref5
     ) => RxVal.a(
     () => F.t(ref1.value, ref2.value, ref3.value, ref4.value, ref5.value),
     ObservableOpImpls.zip(ref1, ref2, ref3, ref4, ref5)
     );
示例#15
0
 [PublicAPI] public static IRxVal <Option <B> > mapT <A, B>(
     this IRxVal <Option <A> > rxMaybeA, Fn <A, B> f
     ) => rxMaybeA.map(maybeA => maybeA.map(f));
示例#16
0
 public static IRxVal <A> filter <A>(this IRxVal <A> rx, Fn <A, bool> predicate, A onFiltered) =>
 rx.map(RxVal.filterMapper(predicate, onFiltered));
示例#17
0
 // TODO: test
 /// <summary>
 /// Convert <see cref="IRxVal{A}"/> to <see cref="IObservable{B}"/>.
 ///
 /// Useful for converting from <see cref="IRxVal{A}"/> to event source. For example:
 ///
 /// <code><![CDATA[
 ///   someRxVal.map(_ => F.unit)
 /// ]]></code>
 ///
 /// would only emit one event, because the result of a map would be a <see cref="IRxVal{A}"/>
 /// that has a <see cref="Unit"/> type, which by it's definition only has one value.
 ///
 /// Thus we'd need to use
 /// <code><![CDATA[
 ///   someRxVal.toEventSource(_ => F.unit)
 /// ]]></code>
 /// </summary>
 public static IObservable <B> toEventSource <A, B>(
     this IRxVal <A> rxVal, Fn <A, B> mapper
     ) => new Observable <B>(onEvent =>
                             rxVal.subscribe(NoOpDisposableTracker.instance, v => onEvent(mapper(v)))
                             );
示例#18
0
 public static IObservable <Unit> toEventSource <A>(this IRxVal <A> o) =>
 o.toEventSource(_ => F.unit);
示例#19
0
 public static IRxVal <Option <B> > optFlatMap <A, B>(
     this IRxVal <Option <A> > source, Fn <A, IRxVal <B> > extractor
     ) =>
 source.optFlatMap(a => extractor(a).map(b => b.some()));
示例#20
0
 public static IRxVal <Option <B> > optFlatMap <A, B>(
     this IRxVal <Option <A> > source, Fn <A, Option <IRxVal <Option <B> > > > extractor
     ) =>
 source.flatMap(aOpt =>
                aOpt.flatMap(extractor).getOrElse(RxVal.cached(F.none <B>()))
                );
示例#21
0
 public static IRxVal <Option <B> > optMap <A, B>(
     this IRxVal <Option <A> > source, Fn <A, B> mapper
     ) => source.map(aOpt => aOpt.map(mapper));