Должен ли магистральный маршрутизатор или представление обрабатывать выборку данных и отображать состояние загрузки?

Во многих местах в моем приложении происходит следующая картина:

User clicks some link triggering navigation Data needs to be fetched to render the view UI design requires a "loading" spinner to be shown while data is fetched Once the data is fetched we show the rendered view

Я пробовал оба из следующих шаблонов реализации:

Router handles fetching

Router tells the container view to show the loading spinner Router loads any collections/models Router tells the container view to hide the loading spinner Router passes the collections/models to the view and renders it

View handles fetching

Router just creates and renders the view The view fetches the collections and models it needs When the view is first rendered, it just shows the loading spinner since the data is still loading When the data arrives, the models/collections fire events and the view is bound to those so it re-renders itself, thus hiding the loading spinner and showing the full view

Мне не нравится # 1, так как маршрутизатор становится гигантским шаром логики выборки Model / Collection и, кажется, несет слишком большую ответственность. # 2 кажется лучшим распределением обязанностей (маршрутизатор просто решает, какое представление показывать, просмотр выясняет, какие данные ему нужно получить), но это действительно делает представление более сложным, так как теперь оно является состоящим.

Что думает сообщество StackOverflow? 1, 2 или что-то еще?

Ответы на вопрос(2)

Ваш ответ на вопрос