A
A
AndNovak2016-12-20 19:23:31
WPF
AndNovak, 2016-12-20 19:23:31

How does the GetData method work?

I understand with MVVM, and specifically with Caliburn Micro. Based on an example . I would like to clarify one point.
In the BookService class, the author creates the GetData method

public void GetData(Action<BindableCollection<IBook>, Exception> callback)
    {
        callback(_books, null);
    }

And then calls this method on the ShellViewModel like this
public ShellViewModel(IBookService dataService)
    {
        _bookDataService = dataService;

        _bookDataService.GetData(
            (items, error) =>
            {
                Books = items;
            });
    }
 public BindableCollection<IBook> Books { get; set; }

As far as I understand, this method loads data into the Book collection, but I don’t quite understand how it does it. Please tell me how this method works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2016-12-21
@AndNovak

В данный метод пихается коллбэк, метод, который вернет данные.
Далее, GetData вызывает данный коллбэк, и передает в него данные в виде коллекции _books, которая сформирована где-то в недрах BookService.
Сам коллбэк представлен анонимной функцией, которая выполняет только то, что присваивает свойству Books класса ShellViewModel значение items, а по сути, все те же _books из BookService.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question