Can.Control vs. can.Component

This is probably an easy one, but thought that I would ask anyway…

Have been away from CanJS for a while now on other projects, and decided to revisit for a new project and have noticed that there has been a ton of great work done since I have been away. So far I am really enjoying my experience… :smile:

Anyway my question is whether can.Control will eventually be replaced by can.Component or whether both will continue forward. There just seems to be some overlap between the two with can.Component getting most of the attention.

I used to use can.Control to wrap custom controls as well as widgets for easy re-use, but can now do the same with components and in a more declarative way. Also used to use it to better organize and handle routes, but this appears to be a depreciated method for routing as I see new examples using state maps in conjunction with component driven stache templates.

I just want to make sure that when we start our project that we are following best practices…

Could someone give me a quick explanation of when to use one over the other?

1 Like

I think both can.Component and can.Control will continue to exist for the foreseeable future. There’s no reason to deprecate can.Control as it’s used a bit internally.

For building applications we almost always use can.Component now for UI widgets.

There are 2 places where now you might still use a can.Control. One is if you are using can.view.attr, Controls can be useful when paired with that:

can.view.attr("foo", function(el, attrData){
  new SomeControl(el, { scope: attrData.scope });

This gives you unbinding for free.

The other place where you might still use can.Control (although I haven’t come across it personally) is if you had something like a large grid where each cell is a component. For performance reasons it might be better to use can.Control for those cells rather than can.Component.

1 Like

Actually that explanation is very makes a lot of sense and answers my question. I appreciate the help and feedback…