예제 #1
0
        public IObservable <Position> GetPosition(bool includeHeading = false)
        {
            var ret = _latestPosition.Take(1).Multicast(new AsyncSubject <Position>());

            ret.Connect();
            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Pops the root and notifies observers.
        /// </summary>
        /// <typeparam name="T">The view model type.</typeparam>
        /// <param name="stackSubject">The stack subject.</param>
        /// <exception cref="InvalidOperationException">Stack is empty.</exception>
        protected static void PopRootAndTick <T>(BehaviorSubject <IImmutableList <T> > stackSubject)
        {
            IImmutableList <T> poppedStack = ImmutableList <T> .Empty;

            if (stackSubject?.Value == null || !stackSubject.Value.Any())
            {
                throw new InvalidOperationException("Stack is empty.");
            }

            stackSubject
            .Take(1)
            .Where(stack => stack != null)
            .Subscribe(stack =>
            {
                if (stack.Count > 1)
                {
                    poppedStack = stack.RemoveRange(stack.IndexOf(stack[1]), stack.Count - 1);
                }
                else
                {
                    poppedStack = stack;
                }
            });

            stackSubject.OnNext(poppedStack);
        }
예제 #3
0
        public void Take_DecrementsCountFirst()
        {
            var k = new BehaviorSubject <bool>(true);

            k.Take(1).Subscribe(b => k.OnNext(!b));

            //
            // No assert needed; test will stack overflow for failure.
            //
        }
예제 #4
0
        public void Test4()
        {
            IObservable <int> CreateRecursive(int count)
            {
                var source   = new BehaviorSubject <int>(0);
                var transfer = source.Take(count - 1).Select(x => ++ x);

                return(Observable.Create <int>(observer => new CompositeDisposable
                {
                    source.Subscribe(observer),
                    transfer.Subscribe(source),
                    source
                }));
            }

            var res = CreateRecursive(5).ToEnumerable();

            CollectionAssert.AreEqual(new [] { 0, 1, 2, 3, 4 }, res);
        }
예제 #5
0
        /// <summary>
        /// Pops the root and notifies observers.
        /// </summary>
        /// <typeparam name="T">The view model type.</typeparam>
        /// <param name="stackSubject">The stack subject.</param>
        /// <param name="disposable">The disposable.</param>
        /// <exception cref="InvalidOperationException">Stack is empty.</exception>
        protected static void PopRootAndTick <T>(BehaviorSubject <IImmutableList <T> > stackSubject, CompositeDisposable disposable)
        {
            IImmutableList <T> poppedStack = ImmutableList <T> .Empty;

            if (stackSubject == null || stackSubject.Value.Count == 0)
            {
                throw new InvalidOperationException("Stack is empty.");
            }

            stackSubject
            .Take(1)
            .Where(stack => stack != null)
            .Subscribe(stack =>
            {
                if (stack.Count > 1)
                {
                    poppedStack = stack.RemoveRange(stack.IndexOf(stack[1]), stack.Count - 1);

                    foreach (T popped in stack.RemoveRange(poppedStack).Reverse())
                    {
                        if (popped == null)
                        {
                            continue;
                        }

                        popped.InvokeViewModelAction <IDestructible>(x => x.Destroy());
                    }
                }
                else
                {
                    poppedStack = stack;
                }
            })
            .DisposeWith(disposable);

            stackSubject.OnNext(poppedStack);
        }