示例#1
0
        public IssueMilestonesViewModel(
            Func <Task <IReadOnlyList <Milestone> > > loadMilestones,
            Func <Task <Issue> > loadIssue,
            Func <IssueUpdate, Task <Issue> > updateIssue
            )
        {
            var milestones = new ReactiveList <Milestone>();

            Milestones = milestones.CreateDerivedCollection(x =>
            {
                var vm = new IssueMilestoneItemViewModel(x);
                if (_selectedMilestone != null)
                {
                    vm.IsSelected = x.Number == _selectedMilestone.Number;
                }
                vm.GoToCommand.Subscribe(_ =>
                {
                    var milestone = vm.IsSelected ? (int?)vm.Number : null;
                    updateIssue(new IssueUpdate {
                        Milestone = milestone
                    }).ToBackground();
                });
                return(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _selectedMilestone = (await loadIssue()).Milestone;
                milestones.Reset(await loadMilestones());
            });
        }
 private IssueMilestoneItemViewModel CreateItemViewModel(Milestone x)
 {
     var vm = new IssueMilestoneItemViewModel(x);
     vm.IsSelected = x.Number == Selected?.Number;
     vm.GoToCommand.Subscribe(_ => {
         Selected = vm.IsSelected ? x : null;
         SaveCommand.ExecuteIfCan();
     });
     return vm;
 }
        private IssueMilestoneItemViewModel CreateItemViewModel(Milestone x)
        {
            var vm = new IssueMilestoneItemViewModel(x);

            vm.IsSelected = x.Number == Selected?.Number;
            vm.GoToCommand.Subscribe(_ => {
                Selected = vm.IsSelected ? x : null;
                SaveCommand.ExecuteIfCan();
            });
            return(vm);
        }
        public IssueMilestonesViewModel(Func<Task<IReadOnlyList<Milestone>>> loadMilestones)
        {
            DismissCommand = ReactiveCommand.Create();

            var milestones = new ReactiveList<Milestone>();
            Milestones = milestones.CreateDerivedCollection(x => {
                var vm = new IssueMilestoneItemViewModel(x);
                vm.IsSelected = x.Number == Selected?.Number;
                vm.GoToCommand
                    .Select(_ => vm.IsSelected ? x : null)
                    .Subscribe(milestone =>  {
                        foreach (var a in Milestones.Where(y => y != vm))
                            a.IsSelected = false;
                        Selected = milestone;
                        DismissCommand.ExecuteIfCan();
                    });
                return vm;
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                milestones.Reset(await loadMilestones());
            });
        }
        public IssueMilestonesViewModel(
            Func <Task <IReadOnlyList <Milestone> > > loadMilestones,
            Func <Task <Milestone> > currentMilestone,
            Func <Milestone, Task> updateIssue
            )
        {
            DismissCommand = ReactiveCommand.Create();

            var milestones = new ReactiveList <Milestone>();

            Milestones = milestones.CreateDerivedCollection(x =>
            {
                var vm = new IssueMilestoneItemViewModel(x);
                if (_selectedMilestone != null)
                {
                    vm.IsSelected = x.Number == _selectedMilestone.Number;
                }
                vm.GoToCommand
                .Select(_ => vm.IsSelected ? x : null)
                .Subscribe(milestone =>
                {
                    foreach (var a in Milestones.Where(y => y != vm))
                    {
                        a.IsSelected = false;
                    }
                    updateIssue(milestone).ToBackground();
                    DismissCommand.ExecuteIfCan();
                });
                return(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _selectedMilestone = (await currentMilestone());
                milestones.Reset(await loadMilestones());
            });
        }