예제 #1
0
        public TodoService(TodoManager todoManager, TodoItemRepository todoItemRepository)
        {
            this.TodoManager = todoManager;
            this.TodoItemRepository = todoItemRepository;

            this.TodoManager.ChangedAsObservable
                .Throttle(TimeSpan.FromMilliseconds(10))
                .ObserveOnUIDispatcher()
                .Subscribe(x =>
                {
                    this.TodoItemRepository.Save(x);
                });
        }
예제 #2
0
        public MainPageViewModel(TodoManager todoManager, TodoService todoService)
        {
            this.TodoManager = todoManager;
            this.TodoService = todoService;

            this.AddTodoItemCommand = this.InputTodoItem
                .Select(x => x.HasErrors)
                .Switch()
                .Select(x => !x)
                .ToReactiveCommand();
            this.AddTodoItemCommand
                .Select(_ => this.InputTodoItem.Value)
                .Subscribe(x =>
                {
                    this.TodoService.AddTodoItem(x);
                    this.InputTodoItem.Value = new TodoItemViewModel();
                });

            this.TodoItems = this.TodoManager
                .ObserveProperty(x => x.CurrentView)
                .Do(_ => this.TodoItems?.Value?.Dispose())
                .Select(x => x.ToReadOnlyReactiveCollection(y => new TodoItemViewModel(y)))
                .ToReactiveProperty();

            this.ShowAllCommand = this.TodoManager.ObserveProperty(x => x.ViewType)
                .Select(x => x != ViewType.All)
                .ToReactiveCommand();
            this.ShowAllCommand.Subscribe(_ => this.TodoService.SetAllCurrentView());

            this.ShowActiveCommand = this.TodoManager.ObserveProperty(x => x.ViewType)
                .Select(x => x != ViewType.Active)
                .ToReactiveCommand();
            this.ShowActiveCommand.Subscribe(_ => this.TodoService.SetActiveCurrentView());

            this.ShowCompletedCommand = this.TodoManager.ObserveProperty(x => x.ViewType)
                .Select(x => x != ViewType.Completed)
                .ToReactiveCommand();
            this.ShowCompletedCommand.Subscribe(_ => this.TodoService.SetCompletedCurrentView());

            this.ClearCompletedTodoItemCommand = this.TodoManager
                .ChangedAsObservable
                .Select(x => x.Any(y => y.Completed))
                .ToReactiveCommand();
            this.ClearCompletedTodoItemCommand.Subscribe(_ => this.TodoService.ClearCompletedTodoItem());
        }