コード例 #1
0
ファイル: exts.cs プロジェクト: Marwan0/tlplib
        // 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);
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: Marwan0/tlplib
        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);
        }
コード例 #3
0
ファイル: PrefValue.cs プロジェクト: CarlosMeloStuff/tlplib
        // 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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #6
0
ファイル: ASync.cs プロジェクト: ArnasJ/tlplib
        /**
         * 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);
        }
コード例 #7
0
ファイル: Extensions.cs プロジェクト: Marwan0/tlplib
        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);
        }
コード例 #8
0
ファイル: FutureTest.cs プロジェクト: Marwan0/tlplib
        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);
        }
コード例 #9
0
ファイル: DFBind.cs プロジェクト: Hengle/Tetris-1
        /*********** 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();
            }));
        }
コード例 #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;
                }
            }
                );
        }