Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : I'm confused what can.Components are meant for

$
0
0
The really big advantage of can.Component is it's nestability and declarative nature. Previously, if you had the need for sub-controllers, you were stuck either setting them up outside of your template, or taking the unconventional route of using long form data tags to set attributes just so that the element wouldn't teardown on changes. That was a huge deal. Perhaps even more importantly, you can use can.components to create a hierarchical scope, so that many components can interact in a loose manner, and therefore are more recyclable. For example, you could have an edit screen containing very generic components for query building, pagination, re-ording of items etc, that can modify the scope of the top level model, regardless of what the model is.

In the example Justin posted, you could also accomplish that by making a notifications map, that is observed by your component, without ever needing to couple the two. Separating your logic and decoupling really matters in larger projects, or for recycling work.

Viewing all articles
Browse latest Browse all 3491

Trending Articles