Exemplo n.º 1
0
        public TodoItemsListVm(ITodoItemsService todoItemsService)
        {
            this.todoItemsService = todoItemsService;

            // Firstly get all items, and after that watch to changes.
            todoItemsService.GetAll()
            .Select(items => items.Select(todoItem => new TodoItemVm(todoItem)))
            .Do(items => TodoItems.AddRange(items))
            .SelectMany(_ => todoItemsService.TodoItemAdded)
            .Subscribe(todoItem => TodoItems.Add(new TodoItemVm(todoItem)));

            this.WhenAnyValue(x => x.SelectedTodoItem)
            .Where(todoItem => todoItem != null)
            .Select(todoItem => todoItem.Model)
            .SelectMany(todoItem => todoItemsService.SetCurrentTodoItem(todoItem))
            .Subscribe();
        }