K
K
kartio2015-06-19 10:31:53
JavaScript
kartio, 2015-06-19 10:31:53

What is the correct way to work with data in a component?

The question is more about "ideology" since the current implementation works as it is, but something is troubling me that this is a bit wrong. Let's say there is a route for editing a record, the approximate structure is as follows

route: открыть форму записи
   controller: действия (сохранить, удалить)
       component: (форма с полями)
           component: (связи записи с другими записями)
                component: действия со связями
                    button: выбрать существующий элемент - в попапе открывается грид с поиском и пагинацией
                    button: создать новый элемент - в попапе открывается простая формая для создания нового элемента

There is no explicit access to the store in the components (and rightly so), which hints that you do not need to use it there. But in below component I am using
this.container.lookup('store:application').findQuery('item', params); // для поиска элементов
this.container.lookup('store:application').createRecord('item'); // для создания элементов

It works, but still I am tormented by the question of how to do it more correctly, because now everywhere the approach has become such that, firstly, the components should have weak connectivity, and secondly, the data goes down, and the actions go up, that is, In essence, I have to request data somewhere in the route or controller (but initially they don’t need to be loaded, but loaded only by the action-event that came from below) and lowered down (in the same way, we click on the second page in the grid - it went up, the data came from above new ones).
There are examples where the route is built in a special way
author/:id/books
and then you can display a nested layout and work with route data for links and with these forms of the parent root, but if two associations appear in the form, for example (/comments), then this principle of work collapses when you need to display the record fields and all related ones in the form with it elements (books, comments).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question