示例#1
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;
                }
            });
        }
示例#2
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)))
                             );