Exemplo n.º 1
0
        // You should not write to Val when using RxRef
        public static RxRef <A> toRxRef <A>(this PrefVal <A> val)
        {
            var rx = new RxRef <A>(val.value);

            rx.subscribe(v => val.value = v);
            return(rx);
        }
Exemplo n.º 2
0
        public static IRxVal <Option <A> > toRxVal <A>(this Future <A> future)
        {
            var rx = RxRef.a(F.none <A>());

            future.onComplete(a => rx.value = F.some(a));
            return(rx);
        }
Exemplo n.º 3
0
        // You should not write to Val when using RxRef
        public RxRef <A> toRxRef()
        {
            var rx = new RxRef <A>(read);

            rx.subscribe(v => write(v));
            return(rx);
        }
Exemplo n.º 4
0
        public static IRxVal <B> toRxVal <A, B>(this Future <A> future, B whileNotCompleted, Fn <A, B> onCompletion)
        {
            var rx = RxRef.a(whileNotCompleted);

            future.onComplete(a => rx.value = onCompletion(a));
            return(rx);
        }
Exemplo n.º 5
0
        public static IRxVal <A> toRxVal <A>(this Future <A> future, A whileNotCompleted)
        {
            var rx = RxRef.a(whileNotCompleted);

            future.onComplete(a => rx.value = a);
            return(rx);
        }
Exemplo n.º 6
0
        /**
         * Takes a function that transforms an element into a future and
         * applies it to all elements in given sequence.
         *
         * However instead of applying all elements concurrently it waits
         * for the future from previous element to complete before applying
         * the next element.
         *
         * Returns reactive value that can be used to observe current stage
         * of the application.
         **/
        public static IRxVal <Option <B> > inAsyncSeq <A, B>(
            this IEnumerable <A> enumerable, Fn <A, Future <B> > asyncAction
            )
        {
            var rxRef = RxRef.a(F.none <B>());

            inAsyncSeq(enumerable.GetEnumerator(), rxRef, asyncAction);
            return(rxRef);
        }
Exemplo n.º 7
0
        public static IRxVal <A> toRxVal <A>(
            this Future <IRxVal <A> > future, A whileNotCompleted
            )
        {
            var rx = RxRef.a(whileNotCompleted);

            future.onComplete(rx2 => rx2.subscribe(v => rx.value = v));
            return(rx);
        }
Exemplo n.º 8
0
        public void WithRxValInside()
        {
            Promise <IRxVal <int> > p;
            var f = Future <IRxVal <int> > .async(out p);

            var rx = f.toRxVal(0);

            rx.value.shouldEqual(0);
            var rx2 = RxRef.a(100);

            p.complete(rx2);
            rx.value.shouldEqual(100);
            rx2.value = 200;
            rx.value.shouldEqual(200);
        }
Exemplo n.º 9
0
        /*********** Two-way binds ***********/

        public static ISubscription bind <T>(
            this IRxRef <T> subject, IEnumerable <dfCheckbox> checkboxes,
            Fn <T, string> mapper, Fn <string, T> comapper
            )
        {
            var optSubject = RxRef.a(F.some(subject.value));
            var optSubjectSourceSubscription = subject.subscribe(v =>
                                                                 optSubject.value = F.some(v)
                                                                 );
            var optSubjectTargetSubscription = optSubject.subscribe(opt =>
                                                                    opt.each(v => subject.value = v)
                                                                    );

            var bindSubscription = optSubject.bind(checkboxes, mapper, comapper);

            return(new Subscription(() => {
                optSubjectSourceSubscription.unsubscribe();
                optSubjectTargetSubscription.unsubscribe();
                bindSubscription.unsubscribe();
            }));
        }
Exemplo n.º 10
0
        /// <summary>
        /// This class calculates realtimeSinceStartup,
        /// but excludes time intervals when an ad is showing or application is paused
        ///
        /// on android - interstitials usually run on a separate activity (application gets paused/resumed automatically)
        /// on IOS and some android ad networks - application does not get paused, so we need to call `setPaused` ourselves
        /// </summary>
        RealTimeButPauseWhenAdIsShowing()
        {
            var pauseStarted = Time.realtimeSinceStartup;

            externalPause = RxRef.a(false);
            ASync.onAppPause.toRxVal(false).zip(externalPause, F.or2).subscribeWithoutEmit(
                NeverDisposeDisposableTracker.instance,
                paused => {
                isPaused = paused;
                if (paused)
                {
                    pauseStarted = Time.realtimeSinceStartup;
                }
                else
                {
                    var secondsPaused   = Time.realtimeSinceStartup - pauseStarted;
                    totalSecondsPaused += secondsPaused;
                }
            }
                );
        }