Exemple #1
0
        public void BasicForReactivePropertySlim()
        {
            var rp  = new ReactivePropertySlim <string>();
            var rrp = rp.ToReadOnlyReactivePropertySlim();

            rp.Value = "xxxx";
            rp.Dispose();
        }
Exemple #2
0
        public void BindToOneWayTestForReadOnlyRPSlim()
        {
            var source = new ReactivePropertySlim <string>();
            var target = source.ToReadOnlyReactivePropertySlim();
            var obj    = new Poco();

            target.BindTo(obj, o => o.Name);

            obj.Name.IsNull();

            source.Value = "Hello world";
            obj.Name.Is("Hello world");
        }
Exemple #3
0
        public ItemService(IAccountService accountService)
        {
            _accountService = accountService;
            _firestore      = CrossCloudFirestore.Current.Instance;

            Item    = _item.ToReadOnlyReactivePropertySlim();
            Owner   = _owner.ToReadOnlyReactivePropertySlim();
            IsLiked = _isLiked.ToReadOnlyReactivePropertySlim();
            IsOwner = Observable.CombineLatest(Item, _accountService.UserId, (item, userId) => item != null && item.OwnerId == userId)
                      .ToReadOnlyReactivePropertySlim();
            IsLoaded   = _isLoaded.ToReadOnlyReactivePropertySlim();
            IsDeleting = _deletingNotifier.ToReadOnlyReactivePropertySlim();
        }
Exemple #4
0
        public void BindToOnwWayConvertTestForReadOnlyRPSlim()
        {
            var source = new ReactivePropertySlim <int>();
            var target = source.ToReadOnlyReactivePropertySlim();
            var obj    = new Poco();

            target.BindTo(
                obj,
                o => o.Name,
                convert: i => "value is " + i);

            obj.Name.Is("value is 0");

            source.Value = 1;
            obj.Name.Is("value is 1");
        }
        public void UnsubscribeTest()
        {
            var source = new ReactivePropertySlim <int>(mode: ReactivePropertyMode.None);
            var rp     = source.ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.None);

            var collecter = new List <(string, int)>();
            var a         = rp.Select(x => ("a", x)).Subscribe(collecter.Add);
            var b         = rp.Select(x => ("b", x)).Subscribe(collecter.Add);
            var c         = rp.Select(x => ("c", x)).Subscribe(collecter.Add);

            source.Value = 99;
            collecter.Is(("a", 99), ("b", 99), ("c", 99));

            collecter.Clear();
            a.Dispose();

            source.Value = 40;
            collecter.Is(("b", 40), ("c", 40));

            collecter.Clear();
            c.Dispose();

            source.Value = 50;
            collecter.Is(("b", 50));

            collecter.Clear();
            b.Dispose();

            source.Value = 9999;
            collecter.Count.Is(0);

            var d = rp.Select(x => ("d", x)).Subscribe(collecter.Add);

            source.Value = 9;
            collecter.Is(("d", 9));

            rp.Dispose();
        }
        public AccountService()
        {
            _firebaseAuth = CrossFirebaseAuth.Current.Instance;
            _firestore    = CrossCloudFirestore.Current.Instance;

            IsInitialized     = _isInitialized.ToReadOnlyReactivePropertySlim();
            IsLoggedIn        = _isLoggedIn.ToReadOnlyReactivePropertySlim();
            UserId            = _userId.ToReadOnlyReactivePropertySlim();
            UserName          = _userName.ToReadOnlyReactivePropertySlim();
            UserImage         = _userImage.ToReadOnlyReactivePropertySlim();
            ContributionCount = _contributionCount.ToReadOnlyReactivePropertySlim();

            UserId.Select(userId => string.IsNullOrEmpty(userId) ?
                          Observable.Return <User>(null) :
                          _firestore.GetCollection(User.CollectionPath)
                          .GetDocument(userId)
                          .AsObservable()
                          .Select(d => d.ToObject <User>()))
            .Switch()
            .Subscribe(user =>
            {
                if (user != null)
                {
                    _userName.Value          = user.Name;
                    _userImage.Value         = user.Image;
                    _contributionCount.Value = user.ContributionCount;
                }
                else
                {
                    _userName.Value          = null;
                    _userImage.Value         = null;
                    _contributionCount.Value = 0;
                }
            })
            .AddTo(_disposables);
        }
Exemple #7
0
        public SelectPointViewModel()
        {
            MouseLeftDownPoint = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseMovePoint     = new ReactivePropertySlim <RoixBorderPoint>();
            ViewBorderSize     = new ReactivePropertySlim <RoixSize>(mode: ReactivePropertyMode.DistinctUntilChanged);

            var imageSourceSize = MyImage.ToRoixIntSize();

            #region CursorPoint
            CursorBorderPoint = MouseMovePoint.ToReadOnlyReactivePropertySlim();

            CursorPointToModel = CursorBorderPoint
                                 .Where(borderPoint => borderPoint.IsNotZero)
                                 .Select(borderPoint => borderPoint.ConvertToNewBorderInt(imageSourceSize).Point)
                                 .ToReadOnlyReactivePropertySlim();
            #endregion

            #region DoubleClickPoint
            var eventAcceptedTime     = DateTime.Now;
            var mouseDoubleClickPoint = MouseLeftDownPoint
                                        .TimeInterval()
                                        .Skip(1)
                                        .Where(ti =>
            {
                // 前回の MouseDown から一定時間が経過していればダブクリと言わない
                if (ti.Interval > TimeSpan.FromMilliseconds(500))
                {
                    return(false);
                }

                var now = DateTime.Now;

                // 前回のダブクリ受付から一定時間が経過するまでは、次のダブクリを受け付けない
                if (now - eventAcceptedTime < TimeSpan.FromMilliseconds(500))
                {
                    return(false);
                }

                eventAcceptedTime = now;        // ダブクリ受付時間の更新
                return(true);
            })
                                        .Select(x => x.Value)
                                        .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.None);

            // 画像座標系の点(これを基準に管理する)
            var selectedPointOnImage = mouseDoubleClickPoint
                                       .Select(borderPoint =>
            {
                var borderInt = borderPoint.ConvertToNewBorderInt(imageSourceSize);
                return(borderInt.ClipToSize(borderInt.Border - 1));
            })
                                       .ToReadOnlyReactivePropertySlim();

            SinglePoint = selectedPointOnImage
                          .CombineLatest(ViewBorderSize, (intPoint, viewSize) =>
            {
                var leftTop       = intPoint.ConvertToNewBorder(viewSize).Point;
                var halfPixelSize = new RoixIntSize(1).ToRoixBorder(imageSourceSize).ConvertToNewBorder(viewSize).Size / 2d;
                return(leftTop + (RoixVector)halfPixelSize);        // 画素の中央部に点を打つためシフト
            })
                          .ToReadOnlyReactivePropertySlim();

            SinglePointToModel = selectedPointOnImage
                                 .Where(borderPoint => borderPoint.Border.IsNotZero)
                                 .Select(borderRectOnView => borderRectOnView.Point)
                                 .ToReadOnlyReactivePropertySlim();
            #endregion
        }