Is a component bound to a single element?

I'm trying to wrap my head around a Twitter flight. Suppose I have a program page, it has 16 elements related to program management, CRUD operations, AJAX requests, etc. ... Using a twitter flight, I need to create a component for each node element or for the page program and attach each element to a function in a program component?

+4
source share
2 answers

A component is created for each element to which you bind it. If you have a list of DOM nodes, you can call .attachTo on each of them and instantiate a set of components for all nodes.

+3
source

You do not need to attach a component to each node. You can have one component attached to a document that does everything, but it makes sense to break it down into smaller functionalities. IMO, the component must be a function.

For example, you might have a component that interacts with the API through ajax, another that handles views for a particular form, another that manages the contents of the list. Only what one component does is up to you. For portability, reusability and ease of maintenance, it makes sense to keep components small and well defined.

Having said that, you probably don't want to make many, many tiny components. I would not want to create one for each item in the list, but I could create it for each list on the page.

One instance of a component can be attached to a DOM node. Components have access to a complete DOM tree extending from its root node.

+1
source

All Articles